From a66a92af57518eaf96d173b5b045ffc873d92545 Mon Sep 17 00:00:00 2001 From: Artur Harasimiuk Date: Wed, 7 Mar 2018 09:11:53 +0100 Subject: [PATCH] use ImageBase when loading dependency Change-Id: I8033ffcc9391ea809964f3cd3cd60da0c01fe156 --- runtime/os_interface/windows/os_library.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/runtime/os_interface/windows/os_library.cpp b/runtime/os_interface/windows/os_library.cpp index 5a523133a7..10361afd18 100644 --- a/runtime/os_interface/windows/os_library.cpp +++ b/runtime/os_interface/windows/os_library.cpp @@ -39,9 +39,12 @@ namespace Windows { decltype(&LoadLibraryExA) OsLibrary::loadLibraryExA = LoadLibraryExA; decltype(&GetModuleFileNameA) OsLibrary::getModuleFileNameA = GetModuleFileNameA; +extern "C" IMAGE_DOS_HEADER __ImageBase; +__inline HINSTANCE GetModuleHINSTANCE() { return (HINSTANCE)&__ImageBase; } + HMODULE OsLibrary::loadDependency(const std::string &dependencyFileName) const { char dllPath[MAX_PATH]; - DWORD length = getModuleFileNameA(GetModuleHandle(NULL), dllPath, MAX_PATH); + DWORD length = getModuleFileNameA(GetModuleHINSTANCE(), dllPath, MAX_PATH); for (DWORD idx = length; idx > 0; idx--) { if (dllPath[idx - 1] == '\\') { dllPath[idx] = '\0';