summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/wolf/library/loader.h16
-rw-r--r--src/library/loader.c6
-rw-r--r--tests/library/test_loader.c4
3 files changed, 19 insertions, 7 deletions
diff --git a/include/wolf/library/loader.h b/include/wolf/library/loader.h
index 76cf5ee..11d5741 100644
--- a/include/wolf/library/loader.h
+++ b/include/wolf/library/loader.h
@@ -38,10 +38,22 @@ extern "C" {
#include "errors.h"
#include <stddef.h> /* for size_t */
+#if defined _WIN32
+#define WIN32_MEAN_AND_LEAN
+#include <windows.h>
+#endif
+
/* @brief handle representing a shared library
*/
typedef struct wolf_library_t *wolf_library_p;
+/* @brief returned by wolf_library_get_func, cast it to the custom function pointer */
+#ifdef _WIN32
+#define WOLF_LIBRARY_FUNCPTR FARPROC
+#else
+#define WOLF_LIBRARY_FUNCPTR void *
+#endif
+
/**
* Loads a shared library.
*
@@ -75,7 +87,7 @@ wolf_error_t wolf_library_unload( wolf_library_p library );
char *wolf_library_errmsg( const wolf_error_t error, const wolf_library_p library, char *buf, size_t buflen );
/**
- * Gets a symbol (usually a function) from the library object. It has to be
+ * Gets a symbol (a function) from the library object. It has to be
* casted properly to the function you are expecting to call.
*
* @param library the library object
@@ -84,7 +96,7 @@ char *wolf_library_errmsg( const wolf_error_t error, const wolf_library_p librar
*
* @return a pointer to the retrieved symbol
*/
-void *wolf_library_get( const wolf_library_p library, const char *name, wolf_error_t *error );
+WOLF_LIBRARY_FUNCPTR wolf_library_get_func( const wolf_library_p library, const char *name, wolf_error_t *error );
/** @} */ /* @addtogroup wolf_library */
diff --git a/src/library/loader.c b/src/library/loader.c
index b8a3d1b..aa501e3 100644
--- a/src/library/loader.c
+++ b/src/library/loader.c
@@ -130,14 +130,14 @@ char *wolf_library_errmsg( const wolf_error_t error, const wolf_library_p librar
return buf;
}
-void *wolf_library_get( const wolf_library_p l, const char *name, wolf_error_t *error ) {
- void *ret;
+WOLF_LIBRARY_FUNCPTR wolf_library_get_func( const wolf_library_p l, const char *name, wolf_error_t *error ) {
+ WOLF_LIBRARY_FUNCPTR ret;
#if defined HAVE_DLFCN
ret = dlsym( l->handle, name );
#else
#if defined _WIN32
-
+ ret = GetProcAddress( l->handle, name );
#else
#error Not using DLFCN as shared loader. Port first!
#endif
diff --git a/tests/library/test_loader.c b/tests/library/test_loader.c
index a76b093..0eef9f2 100644
--- a/tests/library/test_loader.c
+++ b/tests/library/test_loader.c
@@ -27,7 +27,7 @@ int main( void ) {
char errbuf[512];
typedef int (*multiply_by_two_func)( int );
union { multiply_by_two_func func; void *obj; } alias;
- void *symbol;
+ WOLF_LIBRARY_FUNCPTR symbol;
multiply_by_two_func func;
int res = 0;
@@ -43,7 +43,7 @@ int main( void ) {
* casting doesn't work, see:
* http://en.wikipedia.org/wiki/Dynamic_loading
*/
- symbol = wolf_library_get( library, "multiply_by_two", &error );
+ symbol = wolf_library_get_func( library, "multiply_by_two", &error );
alias.obj = symbol;
func = alias.func;