]> Creatis software - cpPlugins.git/blobdiff - lib/cpPlugins/OS/DLLManager.cxx
Architecture updated.
[cpPlugins.git] / lib / cpPlugins / OS / DLLManager.cxx
diff --git a/lib/cpPlugins/OS/DLLManager.cxx b/lib/cpPlugins/OS/DLLManager.cxx
new file mode 100644 (file)
index 0000000..274c7dc
--- /dev/null
@@ -0,0 +1,53 @@
+#include <cpPlugins/OS/DLLManager.h>
+
+#ifdef cpPlugins_SYS_WINDOWS
+#  include <Windows.h>
+#else // cpPlugins_SYS_WINDOWS
+#  include <dlfcn.h>
+#endif // cpPlugins_SYS_WINDOWS
+
+// -------------------------------------------------------------------------
+void* cpPlugins::OS::DLLManager::
+Load( const std::string& fname, std::string& error )
+{
+  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
+  return( hnd );
+}
+
+// -------------------------------------------------------------------------
+void cpPlugins::OS::DLLManager::
+UnLoad( void* hnd )
+{
+#ifdef cpPlugins_SYS_WINDOWS
+  ::FreeLibrary( ( HMODULE )hnd );
+#else // cpPlugins_SYS_WINDOWS
+  dlclose( hnd );
+#endif // cpPlugins_SYS_WINDOWS
+}
+
+// -------------------------------------------------------------------------
+void* cpPlugins::OS::DLLManager::
+GetFunctionHandle( void* hnd, const std::string& function )
+{
+  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 );
+}
+
+// eof - $RCSfile$