cross::DynamicLibrary::DynamicLibrary(const char* libname): libhandle(NULL) { #ifdef _WIN32 libhandle = LoadLibrary(libname); if(!libhandle) throw( DynamicLibException("Library could not be loaded.") ); #else libhandle = dlopen(libname, RTLD_LOCAL | RTLD_NOW); if(!libhandle) throw( DynamicLibException(std::string("Library could not be loaded -- ") + dlerror() + ".") ); #endif }
DynamicLib::DynamicLib(std::string const &fileName, int flags) { this->_handle = dlopen(("./" + fileName).c_str(), flags); if (!this->_handle) { throw DynamicLibException(dlerror()); } }
void *DynamicLib::symbol(std::string const &sysName) const { void *sym; char *error; sym = dlsym(this->_handle, sysName.c_str()); if ((error = dlerror())) throw DynamicLibException(error); return (sym); }
cross::DynamicLibrary::DynamicLibrary(const char* libname): libhandle(NULL) { #ifdef WIN32 libhandle = LoadLibrary(libname); #else libhandle = dlopen(libname, RTLD_LOCAL | RTLD_NOW); #endif if(!libhandle) throw( DynamicLibException("Library could not be loaded.") ); }
cross::DynamicLibrary::~DynamicLibrary() { if(libhandle) { #ifdef WIN32 FreeLibrary((HINSTANCE)libhandle); #else if(dlclose(libhandle) != 0) throw( DynamicLibException("Library could not be closed.") ); #endif } }
cross::DynamicLibrary::~DynamicLibrary() { if(libhandle) { #ifdef _WIN32 FreeLibrary((HINSTANCE)libhandle); #else if(dlclose(libhandle) != 0) throw( DynamicLibException(std::string("Library could not be closed --") + dlerror() + "." )); #endif } }
void* cross::DynamicLibrary::GetFunction(const char* funcname) { void* func = NULL; if(!libhandle) throw( DynamicLibException("Access to unloaded library.") ); #ifdef WIN32 func = (void*)GetProcAddress((HINSTANCE)libhandle, funcname); #else func = dlsym(libhandle, funcname); #endif return func; }
DynamicLib::~DynamicLib() { if (dlclose(this->_handle)) throw DynamicLibException(dlerror()); }