diff options
Diffstat (limited to 'src/ModuleLoader.hpp')
-rwxr-xr-x[-rw-r--r--] | src/ModuleLoader.hpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/ModuleLoader.hpp b/src/ModuleLoader.hpp index 8ecccc3..e7aae37 100644..100755 --- a/src/ModuleLoader.hpp +++ b/src/ModuleLoader.hpp @@ -7,7 +7,12 @@ #include <stdexcept> #include <typeinfo> +#ifndef _WIN32 #include <dlfcn.h> +#else +#define WIN32_MEAN_AND_LEAN +#include <windows.h> +#endif #include "ModuleRegistry.hpp" @@ -16,7 +21,11 @@ template< typename Interface, typename CtorParams = NullType > struct Module { +#ifndef _WIN32 void *handle; +#else + HMODULE handle; +#endif ModuleRegistry< Interface, CtorParams > *registry; }; @@ -38,16 +47,33 @@ class BaseModuleLoader { Module< Interface, CtorParams> m; for( std::vector<string>::const_iterator it = files.begin( ); it != files.end( ); it++ ) { +#ifndef _WIN32 m.handle = dlopen( it->c_str( ), RTLD_NOW ); +#else + m.handle = LoadLibrary( it->c_str( ) ); +#endif if( !m.handle ) { +#ifndef _WIN32 throw std::runtime_error( dlerror( ) ); +#else + // TODO: error message here + throw std::runtime_error( "Module load error" ); +#endif } std::string registryName = "registry_" + demangle( typeid( Interface ) ); +#ifndef _WIN32 m.registry = static_cast< ModuleRegistry< Interface, CtorParams > *>( dlsym( m.handle, registryName.c_str( ) ) ); +#else + m.registry = ( ModuleRegistry< Interface, CtorParams > *)( GetProcAddress( m.handle, registryName.c_str( ) ) ); +#endif if( !m.registry ) { +#ifndef _WIN32 dlclose( m.handle ); +#else + (void)FreeLibrary( m.handle ); +#endif throw std::runtime_error( "missing module registry" ); } @@ -59,7 +85,11 @@ class BaseModuleLoader { { for( typename mapType::iterator it = m_modules.begin( ); it != m_modules.end( ); it++ ) { if( (*it).second.handle ) { +#ifndef _WIN32 dlclose( (*it).second.handle ); +#else + (void)FreeLibrary( (*it).second.handle ); +#endif (*it).second.handle = 0; } } |