#include <cpPlugins/OS/DLLManager.h>
-
-#ifdef cpPlugins_SYS_WINDOWS
-# include <Windows.h>
-#else // cpPlugins_SYS_WINDOWS
+#ifdef cpExtensions_OS_Windows
+#else // cpExtensions_OS_Windows
# include <dlfcn.h>
-#endif // cpPlugins_SYS_WINDOWS
+#endif // cpExtensions_OS_Windows
// -------------------------------------------------------------------------
void* cpPlugins::OS::DLLManager::
-Load( const std::string& fname, std::string& error )
+Open( const std::string& filename )
{
void* hnd = NULL;
-#ifdef cpPlugins_SYS_WINDOWS
- hnd = ::LoadLibraryA( fname.c_str( ) );
-#else // cpPlugins_SYS_WINDOWS
- hnd = dlopen( fname.c_str( ), RTLD_LAZY | RTLD_GLOBAL );
- if( hnd == NULL )
- error = dlerror( );
- else
- dlerror( );
-#endif // cpPlugins_SYS_WINDOWS
+#ifdef cpExtensions_OS_Windows
+#else // cpExtensions_OS_Windows
+ hnd = dlopen( filename.c_str( ), RTLD_NOW | RTLD_GLOBAL );
+ char* error = dlerror( );
+ if( error != NULL )
+ throw std::runtime_error( error );
+#endif // cpExtensions_OS_Windows
return( hnd );
}
// -------------------------------------------------------------------------
void cpPlugins::OS::DLLManager::
-UnLoad( void* hnd )
+Close( void* hnd )
{
-#ifdef cpPlugins_SYS_WINDOWS
- ::FreeLibrary( ( HMODULE )hnd );
-#else // cpPlugins_SYS_WINDOWS
- dlclose( hnd );
-#endif // cpPlugins_SYS_WINDOWS
+#ifdef cpExtensions_OS_Windows
+#else // cpExtensions_OS_Windows
+ /* TODO: why this clashes with VTK? -> Unregistering of factories.
+ dlclose( hnd );
+ dlerror( );
+ */
+#endif // cpExtensions_OS_Windows
}
// -------------------------------------------------------------------------
void* cpPlugins::OS::DLLManager::
-GetFunctionHandle( void* hnd, const std::string& function )
+Sym( void* hnd, const std::string& symbol )
{
- void* f = NULL;
- if( hnd != NULL )
- {
-#ifdef cpPlugins_SYS_WINDOWS
- f = ::GetProcAddress( ( HMODULE )hnd, function.c_str( ) );
-#else // cpPlugins_SYS_WINDOWS
- f = dlsym( hnd, function.c_str( ) );
-#endif // cpPlugins_SYS_WINDOWS
- } // fi
- return( f );
+ void* sym = NULL;
+#ifdef cpExtensions_OS_Windows
+#else // cpExtensions_OS_Windows
+ sym = dlsym( hnd, symbol.c_str( ) );
+ char* error = dlerror( );
+ if( error != NULL )
+ throw std::runtime_error( error );
+#endif // cpExtensions_OS_Windows
+ return( sym );
}
// eof - $RCSfile$