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
}
예제 #2
0
DynamicLib::DynamicLib(std::string const &fileName, int flags)
{
  this->_handle = dlopen(("./" + fileName).c_str(), flags);
  if (!this->_handle)
    {
      throw DynamicLibException(dlerror());
    }
}
예제 #3
0
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);
}
예제 #4
0
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.") );
}
예제 #5
0
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
	}
}
예제 #7
0
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;
}
예제 #8
0
DynamicLib::~DynamicLib()
{
  if (dlclose(this->_handle))
    throw DynamicLibException(dlerror());
}