From 82c2b858633c9992ce7560a0b21f37329904a300 Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Thu, 20 May 2010 15:53:17 +0200 Subject: got to first error message on Windows (library loader) --- src/Makefile.W32 | 7 ++++++- src/library/loader.c | 47 +++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 51 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/Makefile.W32 b/src/Makefile.W32 index d0f7a99..d606df9 100644 --- a/src/Makefile.W32 +++ b/src/Makefile.W32 @@ -29,11 +29,16 @@ LOG_OBJS = \ SERVICE_OBJS = \ service\service.obj +LIBRARY_OBJS = \ + library\loader.obj + OBJS = \ + errors.obj \ $(THREADING_OBJS) \ $(PORT_OBJS) \ $(LOG_OBJS) \ - $(SERVICE_OBJS) + $(SERVICE_OBJS) \ + $(LIBRARY_OBJS) local_all: $(LIBRARIES) diff --git a/src/library/loader.c b/src/library/loader.c index cf5f0e3..b8a3d1b 100644 --- a/src/library/loader.c +++ b/src/library/loader.c @@ -24,14 +24,24 @@ #include "port/gettext.h" /* for i18n */ #include "port/string.h" /* for strncpy */ -#ifdef HAVE_DLFCN +#if defined HAVE_DLFCN #include /* for dlopen. dlclose functions */ #endif +#if defined _WIN32 +#define WIN32_MEAN_AND_LEAN +#include +#endif + #define INTERNAL_ERRBUF_SIZE 256 struct wolf_library_t { - void *handle; /**< the OS handle for the library */ +#if defined HAVE_DLFCN + void *handle; /**< the OS handle for a library */ +#endif +#if defined _WIN32 + HMODULE handle; /**< the windows handle for a library */ +#endif char errbuf[INTERNAL_ERRBUF_SIZE]; /**< internal buffer to hold the error message * we get with dlerror */ }; @@ -59,7 +69,16 @@ wolf_library_p wolf_library_load( const char *name, wolf_error_t *error ) { return l; } #else +#if defined _WIN32 + l->handle = LoadLibrary( name ); + if( l->handle == NULL ) { + strncpy( l->errbuf, "", INTERNAL_ERRBUF_SIZE ); + *error = WOLF_ERR_INTERNAL; + return l; + } +#else #error Not using DLFCN as shared loader. Port first! +#endif #endif *error = WOLF_OK; @@ -67,17 +86,33 @@ wolf_library_p wolf_library_load( const char *name, wolf_error_t *error ) { } wolf_error_t wolf_library_unload( wolf_library_p l ) { +#if !defined _WIN32 int res = 0; +#else + BOOL res = FALSE; +#endif if( l == NULL || l->handle == NULL ) { return WOLF_ERR_INVALID_STATE; } +#if defined HAVE_DLFCN res = dlclose( l->handle ); if( res != 0 ) { strncpy( l->errbuf, dlerror( ), INTERNAL_ERRBUF_SIZE ); return WOLF_ERR_INTERNAL; } +#else +#if defined _WIN32 + res = FreeLibrary( l->handle ); + if( !res ) { + strncpy( l->errbuf, "", INTERNAL_ERRBUF_SIZE ); + return WOLF_ERR_INTERNAL; + } +#else +#error Not using DLFCN as shared loader. Port first! +#endif +#endif free( l ); l = NULL; @@ -98,7 +133,15 @@ char *wolf_library_errmsg( const wolf_error_t error, const wolf_library_p librar void *wolf_library_get( const wolf_library_p l, const char *name, wolf_error_t *error ) { void *ret; +#if defined HAVE_DLFCN ret = dlsym( l->handle, name ); +#else +#if defined _WIN32 + +#else +#error Not using DLFCN as shared loader. Port first! +#endif +#endif *error = WOLF_OK; return ret; -- cgit v1.2.3-54-g00ecf