Browse Source

get_dso_symbol

David Rose 17 years ago
parent
commit
811c45a786
2 changed files with 20 additions and 0 deletions
  1. 16 0
      dtool/src/dtoolutil/load_dso.cxx
  2. 4 0
      dtool/src/dtoolutil/load_dso.h

+ 16 - 0
dtool/src/dtoolutil/load_dso.cxx

@@ -112,6 +112,12 @@ load_dso_error() {
   return errmsg.str();
 }
 
+void *
+get_dso_symbol(void *handle, const string &name) {
+  // Windows puts a leading underscore in front of the symbol name.
+  return (void *)GetProcAddress((HMODULE)handle, name.c_str());
+}
+
 /* end Win32-specific code */
 
 #elif defined(IS_OSX)
@@ -140,6 +146,11 @@ load_dso_error() {
   return "No error.";
 }
 
+void *
+get_dso_symbol(void *handle, const string &name) {
+  return dlsym(handle, name.c_str());
+}
+
 #else
 /* begin generic code */
 
@@ -169,4 +180,9 @@ load_dso_error() {
   return "No error.";
 }
 
+void *
+get_dso_symbol(void *handle, const string &name) {
+  return dlsym(handle, name.c_str());
+}
+
 #endif

+ 4 - 0
dtool/src/dtoolutil/load_dso.h

@@ -36,5 +36,9 @@ unload_dso(void *dso_handle);
 EXPCL_DTOOL string
 load_dso_error();
 
+// Returns a function pointer or other symbol from a loaded library.
+EXPCL_DTOOL void *
+get_dso_symbol(void *handle, const string &name);
+
 #endif