You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by mt...@apache.org on 2009/05/29 12:04:30 UTC

svn commit: r779911 - /commons/proper/daemon/trunk/src/native/nt/procrun/src/javajni.c

Author: mturk
Date: Fri May 29 10:04:29 2009
New Revision: 779911

URL: http://svn.apache.org/viewvc?rev=779911&view=rev
Log:
Use SetDllDirectory if present in the kernel32.dll for adding the jre upper path to the DLL library path. This should enable to load dependent jvm.dll libraries for XP SP1 and later

Modified:
    commons/proper/daemon/trunk/src/native/nt/procrun/src/javajni.c

Modified: commons/proper/daemon/trunk/src/native/nt/procrun/src/javajni.c
URL: http://svn.apache.org/viewvc/commons/proper/daemon/trunk/src/native/nt/procrun/src/javajni.c?rev=779911&r1=779910&r2=779911&view=diff
==============================================================================
--- commons/proper/daemon/trunk/src/native/nt/procrun/src/javajni.c (original)
+++ commons/proper/daemon/trunk/src/native/nt/procrun/src/javajni.c Fri May 29 10:04:29 2009
@@ -47,6 +47,9 @@
 
 static HANDLE _st_sys_jvmDllHandle = NULL;
 
+DYNOLAD_TYPE_DECLARE(SetDllDirectoryW, WINAPI, BOOL)(LPCWSTR);
+static DYNLOAD_FPTR_DECLARE(SetDllDirectoryW) = NULL;
+
 #define JVM_DELETE_CLAZZ(jvm, cl)                                               \
     APXMACRO_BEGIN                                                              \
     if ((jvm)->lpEnv && (jvm)->##cl.jClazz) {                                   \
@@ -152,6 +155,7 @@
 {
     UINT errMode;
     LPWSTR dllJvmPath = (LPWSTR)szJvmDllPath;
+    DYNLOAD_FPTR_DECLARE(SetDllDirectoryW);
 
     if (!IS_INVALID_HANDLE(_st_sys_jvmDllHandle))
         return TRUE;    /* jvm.dll is already loaded */
@@ -168,6 +172,25 @@
     if (IS_INVALID_HANDLE(_st_sys_jvmDllHandle))
         _st_sys_jvmDllHandle = LoadLibraryExW(dllJvmPath, NULL,
                                               LOAD_WITH_ALTERED_SEARCH_PATH);
+
+    if (IS_INVALID_HANDLE(_st_sys_jvmDllHandle)) {
+        WCHAR  jreBinPath[1024];
+        DWORD  i, l = 0;
+
+        lstrcpynW(jreBinPath, dllJvmPath, 1023);
+        DYNLOAD_FPTR_ADDRESS(SetDllDirectoryW, KERNEL32);
+        for (i = lstrlenW(jreBinPath); i > 0, l < 2; i--) {
+            if (jreBinPath[i] == L'\\' || jreBinPath[i] == L'/') {
+                jreBinPath[i] = L'\0';
+                DYNLOAD_CALL(SetDllDirectoryW)(jreBinPath);
+                l++;
+            }
+        }
+        _st_sys_jvmDllHandle = LoadLibraryExW(dllJvmPath, NULL, 0);
+        if (IS_INVALID_HANDLE(_st_sys_jvmDllHandle))
+            _st_sys_jvmDllHandle = LoadLibraryExW(dllJvmPath, NULL,
+                                                  LOAD_WITH_ALTERED_SEARCH_PATH);
+    }
     /* Restore the error mode signalization */
     SetErrorMode(errMode);
     if (IS_INVALID_HANDLE(_st_sys_jvmDllHandle)) {