From db5ad2e09a6b38e841463dbe7eb076492b62c948 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Tue, 18 Aug 2009 15:58:17 +0200 Subject: Mad funktioniert jetzt unter Windows --- src/Common/ModuleManager.cpp | 40 ++++++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 8 deletions(-) (limited to 'src/Common/ModuleManager.cpp') 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 -#include +#include +#ifndef _WIN32 +# include +#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); } -- cgit v1.2.3