|
@@ -9,20 +9,21 @@
|
|
#include <dlfcn.h>
|
|
#include <dlfcn.h>
|
|
#define LOAD_LIBRARY(lib, flags) dlopen(lib, flags)
|
|
#define LOAD_LIBRARY(lib, flags) dlopen(lib, flags)
|
|
#define LOAD_SYMBOL(handle, sym) dlsym(handle, sym)
|
|
#define LOAD_SYMBOL(handle, sym) dlsym(handle, sym)
|
|
-#define LOAD_ERR() dlerror()
|
|
|
|
|
|
+#define LOAD_ERR() strdup(dlerror())
|
|
#define UNLOAD_LIBRARY(handle) dlclose(handle)
|
|
#define UNLOAD_LIBRARY(handle) dlclose(handle)
|
|
#else
|
|
#else
|
|
#include <windows.h>
|
|
#include <windows.h>
|
|
#define LOAD_LIBRARY(lib, flags) LoadLibrary(lib)
|
|
#define LOAD_LIBRARY(lib, flags) LoadLibrary(lib)
|
|
#define LOAD_SYMBOL(handle, sym) GetProcAddress(handle, sym)
|
|
#define LOAD_SYMBOL(handle, sym) GetProcAddress(handle, sym)
|
|
#define UNLOAD_LIBRARY(handle) FreeLibrary(handle)
|
|
#define UNLOAD_LIBRARY(handle) FreeLibrary(handle)
|
|
-
|
|
|
|
-// TODO - refactor this with proper error message handling on windows
|
|
|
|
-inline static char *LOAD_ERR() {
|
|
|
|
- static char errbuf[8];
|
|
|
|
- snprintf(errbuf, 8, "0x%lx", GetLastError());
|
|
|
|
- return errbuf;
|
|
|
|
-}
|
|
|
|
|
|
+#define LOAD_ERR() ({\
|
|
|
|
+ LPSTR messageBuffer = NULL; \
|
|
|
|
+ size_t size = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, \
|
|
|
|
+ NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)&messageBuffer, 0, NULL); \
|
|
|
|
+ char *resp = strdup(messageBuffer); \
|
|
|
|
+ LocalFree(messageBuffer); \
|
|
|
|
+ resp; \
|
|
|
|
+})
|
|
|
|
|
|
#endif
|
|
#endif
|
|
|
|
|