🛠️🐜 Antkeeper superbuild with dependencies included https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
920 B

  1. #include "config.h"
  2. #include "dynload.h"
  3. #include "strutils.h"
  4. #ifdef _WIN32
  5. #define WIN32_LEAN_AND_MEAN
  6. #include <windows.h>
  7. void *LoadLib(const char *name)
  8. {
  9. std::wstring wname{utf8_to_wstr(name)};
  10. return LoadLibraryW(wname.c_str());
  11. }
  12. void CloseLib(void *handle)
  13. { FreeLibrary(static_cast<HMODULE>(handle)); }
  14. void *GetSymbol(void *handle, const char *name)
  15. { return reinterpret_cast<void*>(GetProcAddress(static_cast<HMODULE>(handle), name)); }
  16. #elif defined(HAVE_DLFCN_H)
  17. #include <dlfcn.h>
  18. void *LoadLib(const char *name)
  19. {
  20. dlerror();
  21. void *handle{dlopen(name, RTLD_NOW)};
  22. const char *err{dlerror()};
  23. if(err) handle = nullptr;
  24. return handle;
  25. }
  26. void CloseLib(void *handle)
  27. { dlclose(handle); }
  28. void *GetSymbol(void *handle, const char *name)
  29. {
  30. dlerror();
  31. void *sym{dlsym(handle, name)};
  32. const char *err{dlerror()};
  33. if(err) sym = nullptr;
  34. return sym;
  35. }
  36. #endif