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