Added SDL_GetLoadedModule to do the equivalent of GetModuleHandle/dlload(NOLOAD)
authorSam Lantinga <slouken@libsdl.org>
Thu, 13 Feb 2014 11:05:24 -0800
changeset 8210 581caa876b2e
parent 8209 56e9c709db7e
child 8211 089bc02a5e4b
Added SDL_GetLoadedModule to do the equivalent of GetModuleHandle/dlload(NOLOAD) CR: Jorgen
include/SDL_loadso.h
src/loadso/dlopen/SDL_sysloadso.c
src/loadso/windows/SDL_sysloadso.c
--- a/include/SDL_loadso.h	Wed Feb 12 18:12:14 2014 -0300
+++ b/include/SDL_loadso.h	Thu Feb 13 11:05:24 2014 -0800
@@ -58,6 +58,16 @@
 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().
--- a/src/loadso/dlopen/SDL_sysloadso.c	Wed Feb 12 18:12:14 2014 -0300
+++ b/src/loadso/dlopen/SDL_sysloadso.c	Thu Feb 13 11:05:24 2014 -0800
@@ -42,6 +42,13 @@
 }
 
 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);
--- a/src/loadso/windows/SDL_sysloadso.c	Wed Feb 12 18:12:14 2014 -0300
+++ b/src/loadso/windows/SDL_sysloadso.c	Thu Feb 13 11:05:24 2014 -0800
@@ -47,6 +47,22 @@
 }
 
 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);