Changed the dynamic library open function to allow setting the path of the library to open extra libraries.

This commit is contained in:
Juan Linietsky 2017-11-30 10:00:10 -03:00
parent 831502eddd
commit 9678231b10
6 changed files with 21 additions and 8 deletions

View file

@ -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; }

View file

@ -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());

View file

@ -77,7 +77,7 @@ public:
//virtual VideoMode get_video_mode() const;
//virtual void get_fullscreen_mode_list(List<VideoMode> *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);

View file

@ -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;
}

View file

@ -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<Image> &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 {

View file

@ -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);