SDL2: Replace library loading

--HG--
branch : sdl2
hg/feature/sdl2
kaetemi 11 years ago
parent 87379f87a7
commit bc449abb20

@ -33,13 +33,7 @@ namespace NLMISC
{ {
/// Define the os specific type for dynamic library module handler /// Define the os specific type for dynamic library module handler
#if defined (NL_OS_WINDOWS) typedef void *NL_LIB_HANDLE;
typedef HMODULE NL_LIB_HANDLE;
#elif defined (NL_OS_UNIX)
typedef void* NL_LIB_HANDLE;
#else
# error "You must define the module type on this platform"
#endif
#ifdef NL_OS_WINDOWS #ifdef NL_OS_WINDOWS
// MSCV need explicit tag to export or import symbol for a code module // MSCV need explicit tag to export or import symbol for a code module

@ -16,6 +16,8 @@
#include "stdmisc.h" #include "stdmisc.h"
#include <SDL_loadso.h>
#include "nel/misc/dynloadlib.h" #include "nel/misc/dynloadlib.h"
#include "nel/misc/path.h" #include "nel/misc/path.h"
@ -30,40 +32,20 @@ namespace NLMISC
NL_LIB_HANDLE nlLoadLibrary(const std::string &libName) NL_LIB_HANDLE nlLoadLibrary(const std::string &libName)
{ {
NL_LIB_HANDLE res = 0; NL_LIB_HANDLE res = SDL_LoadObject(libName.c_str());
#ifdef NL_OS_WINDOWS if(res == NULL) nlwarning("Load library '%s' failed: %s", libName.c_str(), NLMISC::formatErrorMessage(NLMISC::getLastError()).c_str());
res = LoadLibrary(libName.c_str());
#elif defined(NL_OS_UNIX)
res = dlopen(libName.c_str(), RTLD_NOW);
#else
# error "You must code nlLoadLibrary() for your platform"
#endif
if(res == 0) nlwarning("Load library '%s' failed: %s", libName.c_str(), NLMISC::formatErrorMessage(NLMISC::getLastError()).c_str());
return res; return res;
} }
bool nlFreeLibrary(NL_LIB_HANDLE libHandle) bool nlFreeLibrary(NL_LIB_HANDLE libHandle)
{ {
#ifdef NL_OS_WINDOWS SDL_UnloadObject(libHandle);
return FreeLibrary(libHandle) > 0;
#elif defined(NL_OS_UNIX)
return dlclose(libHandle) == 0;
#else
# error "You must code nlFreeLibrary() for your platform"
#endif
} }
void *nlGetSymbolAddress(NL_LIB_HANDLE libHandle, const std::string &procName) void *nlGetSymbolAddress(NL_LIB_HANDLE libHandle, const std::string &procName)
{ {
void *res = 0; void *res = SDL_LoadFunction(libHandle, procName.c_str());
#ifdef NL_OS_WINDOWS if(res == NULL) nlwarning("Getting symbol address of '%s' failed: %s", procName.c_str(), NLMISC::formatErrorMessage(NLMISC::getLastError()).c_str());
res = (void *)GetProcAddress(libHandle, procName.c_str());
#elif defined(NL_OS_UNIX)
res = dlsym(libHandle, procName.c_str());
#else
# error "You must code nlGetProcAddress() for your platform"
#endif
if(res == 0) nlwarning("Getting symbol address of '%s' failed: %s", procName.c_str(), NLMISC::formatErrorMessage(NLMISC::getLastError()).c_str());
return res; return res;
} }

Loading…
Cancel
Save