Re #361 : Fixed the Windows side of r3454 (made the legacy menu code a real module) and r3453 (new C++ dynamically loadable module system)
git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@3456 30fe4595-0a0c-4342-8851-515496e4dcbd Former-commit-id: f4d4fd155fb2ebac22e61fd78139f648519a0e4e Former-commit-id: 665b0d8a50476f2cec29b38e12a9a1fd8820e192
This commit is contained in:
parent
d4eca12b39
commit
1e62141893
5 changed files with 21 additions and 19 deletions
|
@ -26,9 +26,9 @@
|
|||
|
||||
#ifdef WIN32
|
||||
# include <windows.h>
|
||||
# define dlopen(soFileName) (void*)LoadLibrary(soFileName)
|
||||
# define dlsym(pvoid) GetProcAddress((HMODULE)pvoid)
|
||||
# define dlclose(pvoid) !FreeLibrary((HMODULE)pvoid)
|
||||
# define dlopen(pszShLibFileName) (void*)LoadLibrary(pszShLibFileName)
|
||||
# define dlsym(pvHandle, pszFuncName) GetProcAddress((HMODULE)pvHandle, pszFuncName)
|
||||
# define dlclose(pvHandle) !FreeLibrary((HMODULE)pvHandle)
|
||||
# define soLibHandle(handle) (void*)handle
|
||||
#else
|
||||
# include <dlfcn.h>
|
||||
|
@ -38,10 +38,10 @@
|
|||
|
||||
// Name and type of the 2 extern "C" module interface functions.
|
||||
typedef int (*tModOpenFunc)(const char*, void*); // Returns 0 on success, !0 otherwise.
|
||||
static const char* pszOpenModuleFuncName = "GfModuleOpen";
|
||||
static const char* pszOpenModuleFuncName = "openGfModule";
|
||||
|
||||
typedef int (*tModCloseFunc)(); // Returns 0 on success, !0 otherwise.
|
||||
static const char* pszCloseModuleFuncName = "GfModuleClose";
|
||||
static const char* pszCloseModuleFuncName = "closeGfModule";
|
||||
|
||||
// Error code decoder.
|
||||
static std::string lastDLErrorString()
|
||||
|
@ -109,7 +109,7 @@ GfModule* GfModule::load(const std::string& strShLibName)
|
|||
{
|
||||
GfLogError("Library %s doesn't export any '%s' function' ; module NOT loaded\n",
|
||||
strShLibName.c_str(), pszOpenModuleFuncName);
|
||||
dlclose(hSOLib);
|
||||
(void)dlclose(hSOLib);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -118,7 +118,7 @@ GfModule* GfModule::load(const std::string& strShLibName)
|
|||
{
|
||||
GfLogError("Library %s '%s' function call failed ; module NOT loaded\n",
|
||||
strShLibName.c_str(), pszOpenModuleFuncName);
|
||||
dlclose(hSOLib);
|
||||
(void)dlclose(hSOLib);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -127,7 +127,7 @@ GfModule* GfModule::load(const std::string& strShLibName)
|
|||
{
|
||||
GfLogError("Library %s '%s' function failed to register the open module ; NOT loaded\n",
|
||||
strShLibName.c_str(), pszOpenModuleFuncName);
|
||||
dlclose(hSOLib);
|
||||
(void)dlclose(hSOLib);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -24,6 +24,11 @@
|
|||
#ifndef __TGF__HPP__
|
||||
#define __TGF__HPP__
|
||||
|
||||
#ifdef _MSC_VER
|
||||
// Disable useless MSVC warnings
|
||||
# pragma warning (disable:4251) // class XXX needs a DLL interface ...
|
||||
#endif
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
|
|
|
@ -49,9 +49,6 @@ ADD_SDL_INCLUDEDIR()
|
|||
ADD_ENET_INCLUDEDIR()
|
||||
|
||||
IF(WIN32)
|
||||
# DLL export stuff under Windows (to avoid .def file)
|
||||
ADD_DEFINITIONS(-DLEGACYMENU_DLL)
|
||||
|
||||
# Ignore some run-time libs to avoid link time warnings and sometimes even crashes.
|
||||
SET(CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_SHARED_LINKER_FLAGS_DEBUG} /NODEFAULTLIB:msvcrt.lib")
|
||||
ENDIF(WIN32)
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
// The LegacyMenu singleton.
|
||||
LegacyMenu* LegacyMenu::_pSelf = 0;
|
||||
|
||||
int GfModuleOpen(const char* pszShLibName, void* hShLibHandle)
|
||||
int openGfModule(const char* pszShLibName, void* hShLibHandle)
|
||||
{
|
||||
// Instanciate the (only) module instance.
|
||||
LegacyMenu::_pSelf = new LegacyMenu(pszShLibName, hShLibHandle);
|
||||
|
@ -41,7 +41,7 @@ int GfModuleOpen(const char* pszShLibName, void* hShLibHandle)
|
|||
return LegacyMenu::_pSelf ? 0 : 1;
|
||||
}
|
||||
|
||||
int GfModuleClose()
|
||||
int closeGfModule()
|
||||
{
|
||||
// Delete the (only) module instance.
|
||||
delete LegacyMenu::_pSelf;
|
||||
|
@ -53,7 +53,7 @@ int GfModuleClose()
|
|||
|
||||
LegacyMenu& LegacyMenu::self()
|
||||
{
|
||||
// Pre-condition : 1 successfull GfModuleOpen call.
|
||||
// Pre-condition : 1 successfull openGfModule call.
|
||||
return *_pSelf;
|
||||
}
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
|
||||
// DLL exported symbols declarator for Windows.
|
||||
#ifdef WIN32
|
||||
# ifdef LEGACYMENU_DLL
|
||||
# ifdef legacymenu_EXPORTS
|
||||
# define LEGACYMENU_API __declspec(dllexport)
|
||||
# else
|
||||
# define LEGACYMENU_API __declspec(dllimport)
|
||||
|
@ -42,8 +42,8 @@
|
|||
|
||||
|
||||
// The C interface of the module.
|
||||
LEGACYMENU_API extern "C" int GfModuleOpen(const char* pszShLibName, void* hShLibHandle);
|
||||
LEGACYMENU_API extern "C" int GfModuleClose();
|
||||
extern "C" int LEGACYMENU_API openGfModule(const char* pszShLibName, void* hShLibHandle);
|
||||
extern "C" int LEGACYMENU_API closeGfModule();
|
||||
|
||||
// The module main class (inherits GfModule, and implements IUserInterface).
|
||||
class LEGACYMENU_API LegacyMenu : public GfModule, public IUserInterface
|
||||
|
@ -112,8 +112,8 @@ protected:
|
|||
IRaceEngine* _piRaceEngine;
|
||||
|
||||
// Make the C interface functions nearly member functions.
|
||||
friend LEGACYMENU_API int GfModuleOpen(const char* pszShLibName, void* hShLibHandle);
|
||||
friend LEGACYMENU_API int GfModuleClose();
|
||||
friend int openGfModule(const char* pszShLibName, void* hShLibHandle);
|
||||
friend int closeGfModule();
|
||||
};
|
||||
|
||||
#endif /* _LEGACYMENU_H_ */
|
||||
|
|
Loading…
Reference in a new issue