Add dynamic loading for Win32.
This commit is contained in:
parent
bd23e23661
commit
ed172fd1e4
|
@ -35,6 +35,10 @@ ifeq ($(HAVE_XML), 1)
|
||||||
LIBS += -lxml2
|
LIBS += -lxml2
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
ifeq ($(DYNAMIC), 1)
|
||||||
|
DEFINES += -DHAVE_DYNAMIC
|
||||||
|
endif
|
||||||
|
|
||||||
ifneq ($(V),1)
|
ifneq ($(V),1)
|
||||||
Q := @
|
Q := @
|
||||||
endif
|
endif
|
||||||
|
|
27
dynamic.c
27
dynamic.c
|
@ -26,18 +26,29 @@
|
||||||
#include <libsnes.hpp>
|
#include <libsnes.hpp>
|
||||||
|
|
||||||
#ifdef HAVE_DYNAMIC
|
#ifdef HAVE_DYNAMIC
|
||||||
#include <dlfcn.h>
|
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
#include <windows.h>
|
||||||
|
#define SYM(x) do { \
|
||||||
|
p##x = ((void*)GetProcAddress(lib_handle, #x)); \
|
||||||
|
if (p##x == NULL) { SSNES_ERR("Failed to load symbol: \"%s\"\n", #x); exit(1); } \
|
||||||
|
} while(0)
|
||||||
|
#else
|
||||||
|
#include <dlfcn.h>
|
||||||
#define SYM(x) do { \
|
#define SYM(x) do { \
|
||||||
p##x = dlsym(lib_handle, #x); \
|
p##x = dlsym(lib_handle, #x); \
|
||||||
if (p##x == NULL) { SSNES_ERR("Failed to load symbol: \"%s\"\n", #x); exit(1); } \
|
if (p##x == NULL) { SSNES_ERR("Failed to load symbol: \"%s\"\n", #x); exit(1); } \
|
||||||
} while(0)
|
} while(0)
|
||||||
|
#endif // _WIN32
|
||||||
#endif
|
#endif // HAVE_DYNAMIC
|
||||||
|
|
||||||
#ifdef HAVE_DYNAMIC
|
#ifdef HAVE_DYNAMIC
|
||||||
|
#ifdef _WIN32
|
||||||
|
static HMODULE lib_handle;
|
||||||
|
#else
|
||||||
static void *lib_handle = NULL;
|
static void *lib_handle = NULL;
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
void (*psnes_init)(void);
|
void (*psnes_init)(void);
|
||||||
|
|
||||||
|
@ -86,7 +97,11 @@ void (*psnes_term)(void);
|
||||||
static void load_dynamic(void)
|
static void load_dynamic(void)
|
||||||
{
|
{
|
||||||
SSNES_LOG("Loading dynamic libsnes from: \"%s\"\n", g_settings.libsnes);
|
SSNES_LOG("Loading dynamic libsnes from: \"%s\"\n", g_settings.libsnes);
|
||||||
|
#ifdef _WIN32
|
||||||
|
lib_handle = LoadLibrary(g_settings.libsnes);
|
||||||
|
#else
|
||||||
lib_handle = dlopen(g_settings.libsnes, RTLD_LAZY);
|
lib_handle = dlopen(g_settings.libsnes, RTLD_LAZY);
|
||||||
|
#endif
|
||||||
if (!lib_handle)
|
if (!lib_handle)
|
||||||
{
|
{
|
||||||
SSNES_ERR("Failed to open dynamic library: \"%s\"\n", g_settings.libsnes);
|
SSNES_ERR("Failed to open dynamic library: \"%s\"\n", g_settings.libsnes);
|
||||||
|
@ -171,6 +186,12 @@ void uninit_dlsym(void)
|
||||||
{
|
{
|
||||||
#ifdef HAVE_DYNAMIC
|
#ifdef HAVE_DYNAMIC
|
||||||
if (lib_handle)
|
if (lib_handle)
|
||||||
|
{
|
||||||
|
#ifdef _WIN32
|
||||||
|
FreeLibrary(lib_handle);
|
||||||
|
#else
|
||||||
dlclose(lib_handle);
|
dlclose(lib_handle);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue