summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbruvzg <7645683+bruvzg@users.noreply.github.com>2017-12-06 14:29:01 +0200
committerRémi Verschelde <rverschelde@gmail.com>2017-12-07 00:20:42 +0100
commit69dca1722f65994794b141ebc05e9b09b4586e03 (patch)
treefcfa90fd1f5d7f325bc1f5f8d4e15fb840299aa6
parentca439056a668d7eca01ac72d769f1b16587da53d (diff)
Use run-time dynamic linking for AddDllDirectory and RemoveDllDirectory to support mingw-w64 build and Windows 7 with KB2533623.
-rw-r--r--platform/windows/os_windows.cpp17
1 files changed, 12 insertions, 5 deletions
diff --git a/platform/windows/os_windows.cpp b/platform/windows/os_windows.cpp
index d62ecc6016..79a760f055 100644
--- a/platform/windows/os_windows.cpp
+++ b/platform/windows/os_windows.cpp
@@ -1629,16 +1629,23 @@ void OS_Windows::_update_window_style(bool repaint) {
Error OS_Windows::open_dynamic_library(const String p_path, void *&p_library_handle, bool p_also_set_library_path) {
+ typedef DLL_DIRECTORY_COOKIE(WINAPI * PAddDllDirectory)(PCWSTR);
+ typedef BOOL(WINAPI * PRemoveDllDirectory)(DLL_DIRECTORY_COOKIE);
+
+ PAddDllDirectory add_dll_directory = (PAddDllDirectory)GetProcAddress(GetModuleHandle("kernel32.dll"), "AddDllDirectory");
+ PRemoveDllDirectory remove_dll_directory = (PRemoveDllDirectory)GetProcAddress(GetModuleHandle("kernel32.dll"), "RemoveDllDirectory");
+
+ bool has_dll_directory_api = ((add_dll_directory != NULL) && (remove_dll_directory != NULL));
DLL_DIRECTORY_COOKIE cookie;
- if (p_also_set_library_path) {
- cookie = AddDllDirectory(p_path.get_base_dir().c_str());
+ if (p_also_set_library_path && has_dll_directory_api) {
+ cookie = add_dll_directory(p_path.get_base_dir().c_str());
}
- p_library_handle = (void *)LoadLibraryExW(p_path.c_str(), NULL, p_also_set_library_path ? LOAD_LIBRARY_SEARCH_DEFAULT_DIRS : 0);
+ p_library_handle = (void *)LoadLibraryExW(p_path.c_str(), NULL, (p_also_set_library_path && has_dll_directory_api) ? LOAD_LIBRARY_SEARCH_DEFAULT_DIRS : 0);
- if (p_also_set_library_path) {
- RemoveDllDirectory(cookie);
+ if (p_also_set_library_path && has_dll_directory_api) {
+ remove_dll_directory(cookie);
}
if (!p_library_handle) {