diff options
| author | Paweł Kołodziejski | 2005-06-05 12:55:33 +0000 | 
|---|---|---|
| committer | Paweł Kołodziejski | 2005-06-05 12:55:33 +0000 | 
| commit | bc65eb8ea51944c13a23ea4a7d1b54d228c5b7ea (patch) | |
| tree | 36a22ed38562b42d97f7d41d059a81522538f95b /base/plugins.cpp | |
| parent | e1aec42c63e4a782d978f21e56ea8d0fce2ed967 (diff) | |
| download | scummvm-rg350-bc65eb8ea51944c13a23ea4a7d1b54d228c5b7ea.tar.gz scummvm-rg350-bc65eb8ea51944c13a23ea4a7d1b54d228c5b7ea.tar.bz2 scummvm-rg350-bc65eb8ea51944c13a23ea4a7d1b54d228c5b7ea.zip | |
added code for loading dynamic plugins(DLLs) for windows
svn-id: r18356
Diffstat (limited to 'base/plugins.cpp')
| -rw-r--r-- | base/plugins.cpp | 40 | 
1 files changed, 39 insertions, 1 deletions
| diff --git a/base/plugins.cpp b/base/plugins.cpp index 695ed6ede6..1dbcf4609f 100644 --- a/base/plugins.cpp +++ b/base/plugins.cpp @@ -47,9 +47,15 @@ typedef DetectedGameList (*DetectFunc)(const FSList &fslist);  #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 @@ public:  };  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 @@ bool DynamicPlugin::loadPlugin() {  }  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 | 
