ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

win32-provider.cpp

Go to the documentation of this file.
00001 /* ScummVM - Graphic Adventure Engine
00002  *
00003  * ScummVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the COPYRIGHT
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #include "common/scummsys.h"
00024 
00025 #if defined(DYNAMIC_MODULES) && defined(_WIN32)
00026 
00027 #include "backends/plugins/win32/win32-provider.h"
00028 #include "backends/plugins/dynamic-plugin.h"
00029 #include "common/debug.h"
00030 #include "common/fs.h"
00031 
00032 #define WIN32_LEAN_AND_MEAN
00033 #include <windows.h>
00034 
00035 
00036 class Win32Plugin : public DynamicPlugin {
00037 private:
00038     static const TCHAR* toUnicode(const char *x) {
00039     #ifndef _WIN32_WCE
00040         return (const TCHAR *)x;
00041     #else
00042         static TCHAR unicodeString[MAX_PATH];
00043         MultiByteToWideChar(CP_ACP, 0, x, strlen(x) + 1, unicodeString, sizeof(unicodeString) / sizeof(TCHAR));
00044         return unicodeString;
00045     #endif
00046     }
00047 
00048 
00049 protected:
00050     void *_dlHandle;
00051 
00052     virtual VoidFunc findSymbol(const char *symbol) {
00053         #ifndef _WIN32_WCE
00054         FARPROC func = GetProcAddress((HMODULE)_dlHandle, symbol);
00055         #else
00056         FARPROC func = GetProcAddress((HMODULE)_dlHandle, toUnicode(symbol));
00057         #endif
00058         if (!func)
00059             debug("Failed loading symbol '%s' from plugin '%s'", symbol, _filename.c_str());
00060 
00061         return (void (*)())func;
00062     }
00063 
00064 public:
00065     Win32Plugin(const Common::String &filename)
00066         : DynamicPlugin(filename), _dlHandle(0) {}
00067 
00068     bool loadPlugin() {
00069         assert(!_dlHandle);
00070 #ifndef _WIN32_WCE
00071         _dlHandle = LoadLibrary(_filename.c_str());
00072 #else
00073         _dlHandle = LoadLibrary(toUnicode(_filename.c_str()));
00074 #endif
00075 
00076         if (!_dlHandle) {
00077             debug("Failed loading plugin '%s' (error code %d)", _filename.c_str(), (int32) GetLastError());
00078             return false;
00079         } else {
00080             debug(1, "Success loading plugin '%s', handle %p", _filename.c_str(), _dlHandle);
00081         }
00082 
00083         return DynamicPlugin::loadPlugin();
00084     }
00085 
00086     void unloadPlugin() {
00087         DynamicPlugin::unloadPlugin();
00088         if (_dlHandle) {
00089             if (!FreeLibrary((HMODULE)_dlHandle))
00090                 debug("Failed unloading plugin '%s'", _filename.c_str());
00091             else
00092                 debug(1, "Success unloading plugin '%s'", _filename.c_str());
00093             _dlHandle = 0;
00094         }
00095     }
00096 };
00097 
00098 
00099 Plugin* Win32PluginProvider::createPlugin(const Common::FSNode &node) const {
00100     return new Win32Plugin(node.getPath());
00101 }
00102 
00103 bool Win32PluginProvider::isPluginFilename(const Common::FSNode &node) const {
00104     // Check the plugin suffix
00105     Common::String filename = node.getName();
00106 #ifndef _WIN32_WCE
00107     if (!filename.hasSuffix(".dll"))
00108 #else
00109     if (!filename.hasSuffix(".plugin"))
00110 #endif
00111         return false;
00112 
00113     return true;
00114 }
00115 
00116 
00117 #endif // defined(DYNAMIC_MODULES) && defined(_WIN32)


Generated on Sat May 25 2019 05:00:56 for ResidualVM by doxygen 1.7.1
curved edge   curved edge