|
|
@ -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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|