diff options
author | Matthias Schiffer <matthias@gamezock.de> | 2009-08-18 15:58:17 +0200 |
---|---|---|
committer | Matthias Schiffer <matthias@gamezock.de> | 2009-08-18 15:58:17 +0200 |
commit | db5ad2e09a6b38e841463dbe7eb076492b62c948 (patch) | |
tree | 5907f6416e35cbd25432a5f1f6dc9664d36aa73c /src/Common/ModuleManager.cpp | |
parent | 5da7b0847bac2a5abec95b9ac1701b74baae8964 (diff) | |
download | mad-db5ad2e09a6b38e841463dbe7eb076492b62c948.tar mad-db5ad2e09a6b38e841463dbe7eb076492b62c948.zip |
Mad funktioniert jetzt unter Windows
Diffstat (limited to 'src/Common/ModuleManager.cpp')
-rw-r--r-- | src/Common/ModuleManager.cpp | 40 |
1 files changed, 32 insertions, 8 deletions
diff --git a/src/Common/ModuleManager.cpp b/src/Common/ModuleManager.cpp index 551229c..057af1f 100644 --- a/src/Common/ModuleManager.cpp +++ b/src/Common/ModuleManager.cpp @@ -28,8 +28,11 @@ #include <modules/modules.h> -#include <dlfcn.h> +#include <boost/thread/locks.hpp> +#ifndef _WIN32 +# include <dlfcn.h> +#endif namespace Mad { namespace Common { @@ -61,7 +64,7 @@ bool ModuleManager::handleConfigEntry(const Core::ConfigEntry &entry, bool handl if(entry[0].getKey().matches("LoadModule") && entry[1].empty()) { if(!loadModule(entry[0][0].c_str())) - application->logf(Core::LoggerBase::ERROR, "Can't load module '%s'.", entry[0][0].c_str()); + application->logf(Core::LoggerBase::LOG_ERROR, "Can't load module '%s'.", entry[0][0].c_str()); return true; } @@ -79,27 +82,43 @@ bool ModuleManager::loadModule(const std::string &name) { ModuleHandle handle = STATIC_MODULE; Module *mod = Modules::loadStaticModule(application, name); + + std::string libname = name + MODULE_SUFFIX; if(!mod) { - handle = dlopen((name + MODULE_SUFFIX).c_str(), RTLD_NOW | RTLD_GLOBAL); +#ifdef WIN32 + handle = LoadLibrary(libname.c_str()); +#else + handle = dlopen(libname.c_str(), RTLD_NOW | RTLD_GLOBAL); +#endif if(!handle) { - application->log(Core::LoggerBase::VERBOSE, std::string("loadModule: Can't open module: ") + std::string(dlerror())); +#ifdef WIN32 + application->logf(Core::LoggerBase::LOG_VERBOSE, "loadModule: Can't open module: Error %u", GetLastError()); +#else + application->log(Core::LoggerBase::LOG_VERBOSE, std::string("loadModule: Can't open module: ") + std::string(dlerror())); +#endif return false; } ModuleLoadFunc loader; - *(void**)&loader = dlsym(handle, (name + "_create").c_str()); + std::string loadername = name + "_create"; + +#ifdef WIN32 + loader = (ModuleLoadFunc)GetProcAddress(handle, loadername.c_str()); +#else + *(void**)&loader = dlsym(handle, loadername.c_str()); +#endif if(!loader) { - application->log(Core::LoggerBase::VERBOSE, "loadModule: Can't open module: Invalid module"); + application->log(Core::LoggerBase::LOG_VERBOSE, "loadModule: Can't open module: Invalid module"); return false; } Module *mod = loader(application); if(!mod) { - application->log(Core::LoggerBase::VERBOSE, "loadModule: Can't open module: Internal module error"); + application->log(Core::LoggerBase::LOG_VERBOSE, "loadModule: Can't open module: Internal module error"); return false; } } @@ -121,8 +140,13 @@ void ModuleManager::unloadModule(const std::string &name) { delete mod->second.second; - if(mod->second.first != STATIC_MODULE) + if(mod->second.first != STATIC_MODULE) { +#ifdef WIN32 + FreeLibrary(mod->second.first); +#else dlclose(mod->second.first); +#endif + } modules.erase(mod); } |