X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FcpPlugins%2FOS%2FDLLManager.cxx;fp=lib%2FcpPlugins%2FOS%2FDLLManager.cxx;h=ba13b368deb470d899f49e9f8c457cba9d3add8c;hb=3c250e0e573d7f08276aefd93a5336f128e6b1a7;hp=0000000000000000000000000000000000000000;hpb=32cfe91acc85230333199444bc712ea86da65c4e;p=cpPlugins.git diff --git a/lib/cpPlugins/OS/DLLManager.cxx b/lib/cpPlugins/OS/DLLManager.cxx new file mode 100644 index 0000000..ba13b36 --- /dev/null +++ b/lib/cpPlugins/OS/DLLManager.cxx @@ -0,0 +1,50 @@ +#include +#ifdef cpExtensions_OS_Windows +#else // cpExtensions_OS_Windows +# include +#endif // cpExtensions_OS_Windows + +// ------------------------------------------------------------------------- +void* cpPlugins::OS::DLLManager:: +Open( const std::string& filename ) +{ + void* hnd = NULL; +#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:: +Close( void* hnd ) +{ +#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:: +Sym( void* hnd, const std::string& symbol ) +{ + 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$