24 #ifndef _SHAREDLIBRARY_H_
25 #define _SHAREDLIBRARY_H_
30 #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
47 inline void*
LoadSharedLibrary(
const std::string& libPrefix, std::string libraryName,
bool quiet )
50 libraryName +=
".dll";
53 HMODULE fileHandle = ::LoadLibraryExA(libraryName.c_str(), NULL, NULL);
54 #elif defined(__linux__)
55 std::string linuxName = libPrefix;
56 linuxName += libraryName +=
".so";
57 void* fileHandle = ::dlopen( linuxName.c_str( ), RTLD_NOW );
58 if( !quiet && !fileHandle )
60 std::cerr << ::dlerror( ) << std::endl;
62 #elif defined(__APPLE__)
63 std::string appleName = libPrefix;
64 appleName += libraryName +=
".dylib";
65 void* fileHandle = ::dlopen( appleName.c_str( ), RTLD_NOW );
66 if( !quiet && !fileHandle )
68 std::cerr << ::dlerror( ) << std::endl;
71 #error "unsupported platform"
91 result = ::FreeLibrary(reinterpret_cast<HMODULE>(libHandle));
94 result = ( ::dlclose( libHandle ) == 0 );
115 if (libHandle == NULL)
118 #if defined( _WIN32 )
119 HMODULE fileHandle =
reinterpret_cast<HMODULE
>(libHandle);
121 void* pFunc =
reinterpret_cast<void*
>(::GetProcAddress(fileHandle, funcName.c_str()));
123 void* pFunc = ::dlsym( libHandle, funcName.c_str( ) );
129 #endif // _SHAREDLIBRARY_H_
int FreeSharedLibrary(void *&libHandle)
Release the handle to the dynamic library.
Definition: loadDynamicLibrary.hpp:85
void * LoadFunctionAddr(void *libHandle, std::string funcName)
Query for function pointer in library.
Definition: loadDynamicLibrary.hpp:113
void * LoadSharedLibrary(const std::string &libPrefix, std::string libraryName, bool quiet)
Create a platform specific handle to a loaded dynamic library.
Definition: loadDynamicLibrary.hpp:47