]> Creatis software - cpPlugins.git/blob - lib/cpPlugins/DLLManager.cxx
4a95fb298c74eb22aa5471bd011bfc3db3aa5dbb
[cpPlugins.git] / lib / cpPlugins / DLLManager.cxx
1 #include <cpPlugins/DLLManager.h>
2
3 #ifdef cpPlugins_SYS_WINDOWS
4 #  include <Windows.h>
5 #else // cpPlugins_SYS_WINDOWS
6 #  include <dlfcn.h>
7 #endif // cpPlugins_SYS_WINDOWS
8
9 // -------------------------------------------------------------------------
10 void* cpPlugins::DLLManager::
11 Load( const std::string& fname, std::string& error )
12 {
13   void* hnd = NULL;
14 #ifdef cpPlugins_SYS_WINDOWS
15   hnd = ::LoadLibraryA( fname.c_str( ) );
16 #else // cpPlugins_SYS_WINDOWS
17   hnd = dlopen( fname.c_str( ), RTLD_LAZY | RTLD_GLOBAL );
18   if( hnd == NULL )
19     error = dlerror( );
20   else
21     dlerror( );
22 #endif // cpPlugins_SYS_WINDOWS
23   return( hnd );
24 }
25
26 // -------------------------------------------------------------------------
27 void cpPlugins::DLLManager::
28 UnLoad( void* hnd )
29 {
30 #ifdef cpPlugins_SYS_WINDOWS
31   ::FreeLibrary( ( HMODULE )hnd );
32 #else // cpPlugins_SYS_WINDOWS
33   dlclose( hnd );
34 #endif // cpPlugins_SYS_WINDOWS
35 }
36
37 // -------------------------------------------------------------------------
38 void* cpPlugins::DLLManager::
39 GetFunctionHandle( void* hnd, const std::string& function )
40 {
41   void* f = NULL;
42   if( hnd != NULL )
43   {
44 #ifdef cpPlugins_SYS_WINDOWS
45     f = ::GetProcAddress( ( HMODULE )hnd, function.c_str( ) );
46 #else // cpPlugins_SYS_WINDOWS
47     f = dlsym( hnd, function.c_str( ) );
48 #endif // cpPlugins_SYS_WINDOWS
49   } // fi
50   return( f );
51 }
52
53 // eof - $RCSfile$