diff --git a/core/os/os.h b/core/os/os.h index c72696fe373..91fbf082bf4 100644 --- a/core/os/os.h +++ b/core/os/os.h @@ -195,7 +195,7 @@ public: virtual void set_ime_position(const Point2 &p_pos) {} virtual void set_ime_intermediate_text_callback(ImeCallback p_callback, void *p_inp) {} - virtual Error open_dynamic_library(const String p_path, void *&p_library_handle) { return ERR_UNAVAILABLE; } + virtual Error open_dynamic_library(const String p_path, void *&p_library_handle,bool p_also_set_library_path=false) { return ERR_UNAVAILABLE; } virtual Error close_dynamic_library(void *p_library_handle) { return ERR_UNAVAILABLE; } virtual Error get_dynamic_library_symbol_handle(void *p_library_handle, const String p_name, void *&p_symbol_handle, bool p_optional = false) { return ERR_UNAVAILABLE; } diff --git a/drivers/unix/os_unix.cpp b/drivers/unix/os_unix.cpp index 0b1aebaaabd..fa208f40ec1 100644 --- a/drivers/unix/os_unix.cpp +++ b/drivers/unix/os_unix.cpp @@ -391,7 +391,7 @@ String OS_Unix::get_locale() const { return locale; } -Error OS_Unix::open_dynamic_library(const String p_path, void *&p_library_handle) { +Error OS_Unix::open_dynamic_library(const String p_path, void *&p_library_handle,bool p_also_set_library_path) { p_library_handle = dlopen(p_path.utf8().get_data(), RTLD_NOW); if (!p_library_handle) { ERR_EXPLAIN("Can't open dynamic library: " + p_path + ". Error: " + dlerror()); diff --git a/drivers/unix/os_unix.h b/drivers/unix/os_unix.h index 5b3fb824f08..325aaf7550d 100644 --- a/drivers/unix/os_unix.h +++ b/drivers/unix/os_unix.h @@ -77,7 +77,7 @@ public: //virtual VideoMode get_video_mode() const; //virtual void get_fullscreen_mode_list(List *p_list) const; - 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); diff --git a/modules/gdnative/gdnative.cpp b/modules/gdnative/gdnative.cpp index 0132ef3c5de..21c24fabd87 100644 --- a/modules/gdnative/gdnative.cpp +++ b/modules/gdnative/gdnative.cpp @@ -144,7 +144,7 @@ bool GDNative::initialize() { } } - Error err = OS::get_singleton()->open_dynamic_library(path, native_handle); + Error err = OS::get_singleton()->open_dynamic_library(path, native_handle,true); if (err != OK) { return false; } diff --git a/platform/windows/os_windows.cpp b/platform/windows/os_windows.cpp index 7c1f733974f..d4612783c75 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 43672972623..e98f8277df6 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);