16#include <boost/algorithm/string/predicate.hpp>
24Logger
g_log(
"DllOpen");
32const std::string LIB_SUFFIX =
".dll";
46 void *handle = LoadLibrary(filePath.c_str());
51 DWORD dw = GetLastError();
53 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, dw,
54 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR)&lpMsgBuf, 0, NULL);
57 size_t n = lstrlen((LPCTSTR)lpMsgBuf) + 40;
59 lpDisplayBuf = (LPVOID)LocalAlloc(LMEM_ZEROINIT,
n *
sizeof(TCHAR));
60 _snprintf((
char *)lpDisplayBuf,
n,
"failed with error %lu: %s", dw, (
char *)lpMsgBuf);
61 g_log.
error() <<
"Could not open library " << filePath <<
": " << (LPCTSTR)lpDisplayBuf <<
'\n';
64 LocalFree(lpDisplayBuf);
78const std::string LIB_SUFFIX =
".so";
79#elif defined __APPLE__
80const std::string LIB_SUFFIX =
".dylib";
89 return boost::starts_with(filename,
LIB_PREFIX) && boost::ends_with(filename, LIB_SUFFIX);
97 void *handle = dlopen(filepath.c_str(), RTLD_NOW | RTLD_GLOBAL);
99 g_log.
error(
"Could not open library " + filepath +
": " + dlerror());
#define UNUSED_ARG(x)
Function arguments are sometimes unused in certain implmentations but are required for documentation ...
static bool isValidFilename(const std::string &filename)
Check if the filename conforms to the expected style for this platform.
static void * openDll(const std::string &filepath)
Static method for opening the shared library.
static void closeDll(void *handle)
Static method for closing the shared library.
void error(const std::string &msg)
Logs at error level.
Logger g_log("DateAndTime")
const std::string LIB_PREFIX