diff options
Diffstat (limited to 'CNativeCode')
-rw-r--r-- | CNativeCode/jawt_misc.c | 65 | ||||
-rw-r--r-- | CNativeCode/jawt_misc.h | 5 | ||||
-rw-r--r-- | CNativeCode/jni12tools.c | 8 |
3 files changed, 67 insertions, 11 deletions
diff --git a/CNativeCode/jawt_misc.c b/CNativeCode/jawt_misc.c index f906ba4..bdf8fe7 100644 --- a/CNativeCode/jawt_misc.c +++ b/CNativeCode/jawt_misc.c @@ -16,40 +16,93 @@ static int gds = 0; static jboolean jawtdebug = JNI_FALSE; +#ifdef _WIN32_ + static HMODULE hDLL_JAWT = 0; +#endif + +#ifdef _X11_ + static void * libHandleJAWT = 0; +#endif + + jboolean LIBAPIENTRY jawt_init (char* jawtLibName) { + #ifdef _WIN32_ - HMODULE lib = LoadLibrary(jawtLibName); - if (lib == NULL) { + + if ( hDLL_JAWT==NULL ) + hDLL_JAWT = LoadLibrary(jawtLibName); + + if ( hDLL_JAWT==NULL ) + { printf(" jawt_init: LoadLibrary failed\n"); return JNI_FALSE; } - JAWT_GetAWT_fn = (JAWT_GetAWT_fn_t*) GetProcAddress(lib, "_JAWT_GetAWT@8"); + + JAWT_GetAWT_fn = (JAWT_GetAWT_fn_t*) + GetProcAddress(hDLL_JAWT, "_JAWT_GetAWT@8"); + if (JAWT_GetAWT_fn == NULL) { printf(" jawt_init: GetProcAddress failed\n"); return JNI_FALSE; } return JNI_TRUE; + #endif #ifdef _X11_ - void* lib = dlopen(jawtLibName, RTLD_LAZY | RTLD_GLOBAL); - if (lib == NULL) { + + if ( libHandleJAWT == NULL ) + libHandleJAWT = dlopen(jawtLibName, RTLD_LAZY | RTLD_GLOBAL); + + if ( libHandleJAWT == NULL) { printf(" jawt_init: dlopen failed\n"); return JNI_FALSE; } - JAWT_GetAWT_fn = (JAWT_GetAWT_fn_t*) dlsym(lib, "JAWT_GetAWT"); + + JAWT_GetAWT_fn = (JAWT_GetAWT_fn_t*) dlsym(libHandleJAWT, "JAWT_GetAWT"); + if (JAWT_GetAWT_fn == NULL) { printf(" jawt_init: dlsym failed\n"); return JNI_FALSE; } + return JNI_TRUE; + #endif return JNI_FALSE; } +void LIBAPIENTRY +jawt_unload () +{ + +#ifdef _WIN32_ + + if ( hDLL_JAWT!=NULL ) + { + JAWT_GetAWT_fn = NULL; + FreeLibrary(hDLL_JAWT); + hDLL_JAWT = NULL; + } + +#endif + +#ifdef _X11_ + + if ( libHandleJAWT != NULL ) + { + JAWT_GetAWT_fn = NULL; + dlClose(libHandleJAWT); + libHandleJAWT = NULL; + } + +#endif + +} + jboolean LIBAPIENTRY jawt_create_offscreen (JNIEnv *env, JAWTDataHolder **ppJData, jboolean verbose) { diff --git a/CNativeCode/jawt_misc.h b/CNativeCode/jawt_misc.h index 293ffa9..4504b46 100644 --- a/CNativeCode/jawt_misc.h +++ b/CNativeCode/jawt_misc.h @@ -59,8 +59,9 @@ jboolean result; } JAWTDataHolder; - LIBAPI jboolean LIBAPIENTRY - jawt_init (char* jawtLibName); + LIBAPI jboolean LIBAPIENTRY jawt_init (char* jawtLibName); + + LIBAPI void LIBAPIENTRY jawt_unload(); LIBAPI jboolean LIBAPIENTRY jawt_create_offscreen (JNIEnv *env, JAWTDataHolder **ppJData, diff --git a/CNativeCode/jni12tools.c b/CNativeCode/jni12tools.c index 09b948a..4a13a52 100644 --- a/CNativeCode/jni12tools.c +++ b/CNativeCode/jni12tools.c @@ -1,7 +1,8 @@ #include <string.h> #include "jnitools.h" -
-#include "gltool.h"
+#include "jawt_misc.h" + +#include "gltool.h" #ifdef __BUILTIN_VA_ARG_INCR /* Special stuff for the SunOS port ... */ @@ -538,7 +539,8 @@ JNI_OnLoad(JavaVM * vm, void *reserved) JNIEXPORT void JNICALL JNI_OnUnload(JavaVM *vm, void *reserved) -{
+{ unloadGLLibrary(); + jawt_unload(); } |