From 9678231b109c333a5273325c8758241310cd27f4 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Thu, 30 Nov 2017 10:00:10 -0300 Subject: Changed the dynamic library open function to allow setting the path of the library to open extra libraries. --- platform/windows/os_windows.cpp | 19 ++++++++++++++++--- platform/windows/os_windows.h | 2 +- 2 files changed, 17 insertions(+), 4 deletions(-) (limited to 'platform') diff --git a/platform/windows/os_windows.cpp b/platform/windows/os_windows.cpp index 7c1f733974..d4612783c7 100644 --- a/platform/windows/os_windows.cpp +++ b/platform/windows/os_windows.cpp @@ -1588,8 +1588,21 @@ void OS_Windows::_update_window_style(bool repaint) { } } -Error OS_Windows::open_dynamic_library(const String p_path, void *&p_library_handle) { - p_library_handle = (void *)LoadLibrary(p_path.utf8().get_data()); +Error OS_Windows::open_dynamic_library(const String p_path, void *&p_library_handle, bool p_also_set_library_path) { + + + DLL_DIRECTORY_COOKIE cookie; + + if (p_also_set_library_path) { + cookie = AddDllDirectory(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_USER_DIRS : 0); + + if (p_also_set_library_path) { + RemoveDllDirectory(cookie); + } + if (!p_library_handle) { ERR_EXPLAIN("Can't open dynamic library: " + p_path + ". Error: " + String::num(GetLastError())); ERR_FAIL_V(ERR_CANT_OPEN); @@ -1954,7 +1967,7 @@ void OS_Windows::set_icon(const Ref &p_icon) { bool OS_Windows::has_environment(const String &p_var) const { - return getenv(p_var.utf8().get_data()) != NULL; + return _wgetenv(p_var.c_str()) != NULL; }; String OS_Windows::get_environment(const String &p_var) const { diff --git a/platform/windows/os_windows.h b/platform/windows/os_windows.h index 4367297262..e98f8277df 100644 --- a/platform/windows/os_windows.h +++ b/platform/windows/os_windows.h @@ -212,7 +212,7 @@ public: virtual void set_borderless_window(int p_borderless); virtual bool get_borderless_window(); - virtual Error open_dynamic_library(const String p_path, void *&p_library_handle); + virtual Error open_dynamic_library(const String p_path, void *&p_library_handle,bool p_also_set_library_path=false); virtual Error close_dynamic_library(void *p_library_handle); virtual Error get_dynamic_library_symbol_handle(void *p_library_handle, const String p_name, void *&p_symbol_handle, bool p_optional = false); -- cgit v1.2.3