Advertisement
obernardovieira

[WIN & UNIX] DLL control (LoadLibrary & GetProcAddress)

Aug 15th, 2013
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.67 KB | None | 0 0
  1. // >>>>>>>>>>   NOT BY ME!!
  2.  
  3.  
  4. #ifdef _WIN32
  5. #include <windows.h>
  6. typedef HANDLE my_lib_t;
  7. #else
  8. #include <dlfcn.h>
  9. typedef void* my_lib_t;
  10. #endif
  11.  
  12. my_lib_t MyLoadLib(const char* szMyLib) {
  13. # ifdef _WIN32
  14.   return ::LoadLibraryA(szMyLib);
  15. # else //_WIN32
  16.   return ::dlopen(szMyLib, RTLD_LAZY);
  17. # endif //_WIN32
  18. }
  19.  
  20. void MyUnloadLib(my_lib_t hMyLib) {
  21. # ifdef _WIN32
  22.   return ::FreeLibrary(hMyLib);
  23. # else //_WIN32
  24.   return ::dlclose(hMyLib);
  25. # endif //_WIN32
  26. }
  27.  
  28. void* MyLoadProc(my_lib_t hMyLib, const char* szMyProc) {
  29. # ifdef _WIN32
  30.   return ::GetProcAddress(hMyLib, szMyProc);
  31. # else //_WIN32
  32.   return ::dlsym(hMyLib, szMyProc);
  33. # endif //_WIN32
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement