Added SDL_GetLoadedModule to do the equivalent of GetModuleHandle/dlload(NOLOAD) CR: Jorgen
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
diff --git a/include/SDL_loadso.h b/include/SDL_loadso.h
index 0359eae..50df510 100644
--- a/include/SDL_loadso.h
+++ b/include/SDL_loadso.h
@@ -58,6 +58,16 @@ extern "C" {
extern DECLSPEC void *SDLCALL SDL_LoadObject(const char *sofile);
/**
+ * This function returns a handle to an already-loaded shared object and
+ * returns a pointer to the object handle. If the object file was not loaded
+ * the function returns NULL. This function adds a reference to the shared
+ * object, so the caller should call SDL_UnloadObject when they are finished
+ * with this reference to ensure that the object can be unloaded.
+ * The 'sofile' parameter is a system dependent name of the object file.
+ */
+extern DECLSPEC void *SDLCALL SDL_GetLoadedObject(const char *sofile);
+
+/**
* Given an object handle, this function looks up the address of the
* named function in the shared object and returns it. This address
* is no longer valid after calling SDL_UnloadObject().
diff --git a/src/loadso/dlopen/SDL_sysloadso.c b/src/loadso/dlopen/SDL_sysloadso.c
index db84222..79df107 100644
--- a/src/loadso/dlopen/SDL_sysloadso.c
+++ b/src/loadso/dlopen/SDL_sysloadso.c
@@ -42,6 +42,13 @@ SDL_LoadObject(const char *sofile)
}
void *
+SDL_GetLoadedObject(const char *sofile)
+{
+ void *handle = dlopen(sofile, RTLD_NOLOAD);
+ return (handle);
+}
+
+void *
SDL_LoadFunction(void *handle, const char *name)
{
void *symbol = dlsym(handle, name);
diff --git a/src/loadso/windows/SDL_sysloadso.c b/src/loadso/windows/SDL_sysloadso.c
index cbbd929..4ff36af 100644
--- a/src/loadso/windows/SDL_sysloadso.c
+++ b/src/loadso/windows/SDL_sysloadso.c
@@ -47,6 +47,22 @@ SDL_LoadObject(const char *sofile)
}
void *
+SDL_GetLoadedObject(const char *sofile)
+{
+ LPTSTR tstr = WIN_UTF8ToString(sofile);
+ void *handle = (void *) GetModuleHandle(tstr);
+
+ /* if we got a handle, call LoadLibrary to get
+ * it again with the ref count incremented.
+ * We do this to match the dlopen version of this function */
+ handle = (void *)LoadLibrary( tstr );
+
+ SDL_free(tstr);
+
+ return handle;
+}
+
+void *
SDL_LoadFunction(void *handle, const char *name)
{
void *symbol = (void *) GetProcAddress((HMODULE) handle, name);