diff options
Diffstat (limited to 'jurt/source/pipe/wrapper/wrapper.c')
-rw-r--r-- | jurt/source/pipe/wrapper/wrapper.c | 51 |
1 files changed, 37 insertions, 14 deletions
diff --git a/jurt/source/pipe/wrapper/wrapper.c b/jurt/source/pipe/wrapper/wrapper.c index e9969bc99378..632b19afa08a 100644 --- a/jurt/source/pipe/wrapper/wrapper.c +++ b/jurt/source/pipe/wrapper/wrapper.c @@ -26,27 +26,50 @@ #include "jni.h" #include "sal/types.h" -static HMODULE module; -static FARPROC getFunction(char const * name) { +static HMODULE module = NULL; +static HINSTANCE hInstDLL = NULL; +static CRITICAL_SECTION CriticalSection; + +void InitWrapper(void) { + #define MAXPATH 512 + wchar_t path[MAXPATH]; + DWORD size; + + size = GetModuleFileNameW(hInstDLL, path, MAXPATH); + if (size == 0) { + abort(); + } + path[size - 5] = L'x'; /* ...\jpipe.dll -> ...\jpipx.dll */ + module = LoadLibraryExW(path, NULL, LOAD_WITH_ALTERED_SEARCH_PATH); + if (module == NULL) { + abort(); + } +} + +static FARPROC getFunction(char const * name) +{ + { + EnterCriticalSection(&CriticalSection); + + if(module == NULL) + InitWrapper(); + + LeaveCriticalSection(&CriticalSection); + } + return GetProcAddress(module, name); } BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) { (void) lpvReserved; - if (fdwReason == DLL_PROCESS_ATTACH) { - wchar_t path[32767]; - DWORD size; - size = GetModuleFileNameW(hinstDLL, path, 32767); - if (size == 0) { - return FALSE; - } - path[size - 5] = L'x'; /* ...\jpipe.dll -> ...\jpipx.dll */ - module = LoadLibraryExW(path, NULL, LOAD_WITH_ALTERED_SEARCH_PATH); - if (module == NULL) { - return FALSE; - } + + if (fdwReason == DLL_PROCESS_ATTACH) + { + InitializeCriticalSection(&CriticalSection); + hInstDLL = hinstDLL; } + return TRUE; } |