[Scummvm-cvs-logs] CVS: scummvm/base plugins.cpp,1.42,1.43 plugins.h,1.27,1.28
Pawel Kolodziejski
aquadran at users.sourceforge.net
Sun Jun 5 05:56:12 CEST 2005
Update of /cvsroot/scummvm/scummvm/base
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16138/base
Modified Files:
plugins.cpp plugins.h
Log Message:
added code for loading dynamic plugins(DLLs) for windows
Index: plugins.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/base/plugins.cpp,v
retrieving revision 1.42
retrieving revision 1.43
diff -u -d -r1.42 -r1.43
--- plugins.cpp 5 Apr 2005 15:07:37 -0000 1.42
+++ plugins.cpp 5 Jun 2005 12:55:33 -0000 1.43
@@ -47,9 +47,15 @@
#define PLUGIN_PREFIX ""
#define PLUGIN_SUFFIX ".plg"
#else
+#ifdef _WIN32
+#define PLUGIN_DIRECTORY ""
+#define PLUGIN_PREFIX ""
+#define PLUGIN_SUFFIX ".dll"
+#else
#error No support for loading plugins on non-unix systems at this point!
#endif
#endif
+#endif
#else
@@ -138,24 +144,44 @@
};
void *DynamicPlugin::findSymbol(const char *symbol) {
-#if defined(UNIX)||defined(__DC__)
+#if defined(UNIX) || defined(__DC__)
void *func = dlsym(_dlHandle, symbol);
if (!func)
warning("Failed loading symbol '%s' from plugin '%s' (%s)", symbol, _filename.c_str(), dlerror());
return func;
#else
+#if defined(_WIN32)
+ void *func = GetProcAddress((HMODULE)_dlHandle, symbol);
+ if (!func)
+ warning("Failed loading symbol '%s' from plugin '%s'", symbol, _filename.c_str());
+ return func;
+#else
#error TODO
#endif
+#endif
}
bool DynamicPlugin::loadPlugin() {
assert(!_dlHandle);
+#if defined(UNIX) || defined(__DC__)
_dlHandle = dlopen(_filename.c_str(), RTLD_LAZY);
if (!_dlHandle) {
warning("Failed loading plugin '%s' (%s)", _filename.c_str(), dlerror());
return false;
}
+#else
+#if defined(_WIN32)
+ _dlHandle = LoadLibrary(_filename.c_str());
+
+ if (!_dlHandle) {
+ warning("Failed loading plugin '%s'", _filename.c_str());
+ return false;
+ }
+#else
+#error TODO
+#endif
+#endif
// Query the plugin's name
NameFunc nameFunc = (NameFunc)findSymbol("PLUGIN_name");
@@ -195,11 +221,23 @@
}
void DynamicPlugin::unloadPlugin() {
+#if defined(UNIX) || defined(__DC__)
if (_dlHandle) {
if (dlclose(_dlHandle) != 0)
warning("Failed unloading plugin '%s' (%s)", _filename.c_str(), dlerror());
}
}
+#else
+#if defined(_WIN32)
+ if (_dlHandle) {
+ if (!FreeLibrary((HMODULE)_dlHandle))
+ warning("Failed unloading plugin '%s'", _filename.c_str());
+ }
+}
+#else
+#error TODO
+#endif
+#endif
#endif // DYNAMIC_MODULES
Index: plugins.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/base/plugins.h,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -d -r1.27 -r1.28
--- plugins.h 5 Apr 2005 15:07:38 -0000 1.27
+++ plugins.h 5 Jun 2005 12:55:33 -0000 1.28
@@ -92,10 +92,10 @@
#else
#define REGISTER_PLUGIN(ID,name) \
extern "C" { \
- const char *PLUGIN_name() { return name; } \
- GameList PLUGIN_getSupportedGames() { return Engine_##ID##_gameList(); } \
- Engine *PLUGIN_createEngine(GameDetector *detector, OSystem *syst) { return Engine_##ID##_create(detector, syst); } \
- DetectedGameList PLUGIN_detectGames(const FSList &fslist) { return Engine_##ID##_detectGames(fslist); } \
+ PLUGIN_EXPORT const char *PLUGIN_name() { return name; } \
+ PLUGIN_EXPORT GameList PLUGIN_getSupportedGames() { return Engine_##ID##_gameList(); } \
+ PLUGIN_EXPORT Engine *PLUGIN_createEngine(GameDetector *detector, OSystem *syst) { return Engine_##ID##_create(detector, syst); } \
+ PLUGIN_EXPORT DetectedGameList PLUGIN_detectGames(const FSList &fslist) { return Engine_##ID##_detectGames(fslist); } \
}
#endif
More information about the Scummvm-git-logs
mailing list