From 66d31e1f048e8d90d614c19fbcdabc028c431bc7 Mon Sep 17 00:00:00 2001 From: Perry Werneck Date: Tue, 13 Aug 2019 09:43:38 -0300 Subject: [PATCH] Fixing load of delayed library. --- client/src/session/local/session.cc | 69 ++++++++++++++++++++++++++++++++------------------------------------- client/src/testprogram/testprogram.cc | 2 +- configure.ac | 2 +- 3 files changed, 34 insertions(+), 39 deletions(-) diff --git a/client/src/session/local/session.cc b/client/src/session/local/session.cc index a2b3018..4772470 100644 --- a/client/src/session/local/session.cc +++ b/client/src/session/local/session.cc @@ -69,6 +69,8 @@ HANDLE hEventLog = RegisterEventSource(NULL, PACKAGE_NAME); + debug(msg," rc=",rc); + if(hEventLog) { char username[UNLEN + 1]; @@ -142,8 +144,7 @@ if(!initialized) { // Get application DATADIR - - // https://github.com/curl/curl/blob/master/lib/system_win32.c + LSTATUS rc; char datadir[4096]; HKEY hKey = openKey(); @@ -155,55 +156,48 @@ unsigned long datatype; // #defined in winnt.h (predefined types 0-11) - if(RegQueryValueExA(hKey,"InstallLocation",NULL,&datatype,(LPBYTE) datadir,&datalen) != ERROR_SUCCESS) { + rc = RegQueryValueExA(hKey,"InstallLocation",NULL,&datatype,(LPBYTE) datadir,&datalen); + if(rc != ERROR_SUCCESS) { // Can't get DATADIR + write_log("Can't get Install Location", (int) rc); *datadir = 0; } - RegCloseKey(hKey); } - if(*datadir) { - - HMODULE kernel = - LoadLibrary("kernel32.dll"); - - if(kernel) { - - HANDLE WINAPI (*AddDllDirectory)(PCWSTR) = - (HANDLE WINAPI (*)(PCWSTR)) GetProcAddress(kernel,"AddDllDirectory"); - - //BOOL WINAPI (*RemoveDllDirectory)(HANDLE) = - // (BOOL WINAPI (*)(HANDLE)) GetProcAddress(kernel,"RemoveDllDirectory"); - - if(AddDllDirectory) { - - wchar_t *path = (wchar_t *) malloc(sizeof(datadir)*sizeof(wchar_t)); - mbstowcs(path, datadir, 4095); - - if(!AddDllDirectory(path)) { - write_log("AddDllDirectory has failed"); - } - - free(path); - - } else { - - write_log("Can't find AddDllDirectory@kernel32.dll"); - - } - - FreeLibrary(kernel); +#ifdef DEBUG + debug("Datadir=\"",datadir,"\""); +#endif // DEBUG + if(*datadir) { - } else { + wchar_t *path = (wchar_t *) malloc(sizeof(datadir)*sizeof(wchar_t)); + mbstowcs(path, datadir, 4095); - write_log("Can't load kernel32.dll"); + if(!SetDefaultDllDirectories(LOAD_LIBRARY_SEARCH_USER_DIRS)) { + write_log("SetDefaultDllDirectories has failed"); + } +#ifdef DEBUG + else { + debug("SetDefaultDllDirectories has suceeded"); + } +#endif + if(!AddDllDirectory(path)) { + string msg = "Can't add "; + msg += datadir; + msg += " to directory path"; + write_log(msg.c_str()); } +#ifdef DEBUG + else { + debug("AddDllDirectory has suceeded"); + } +#endif + free(path); } @@ -215,6 +209,7 @@ #endif // _WIN32 this->hSession = lib3270_session_new(""); + lib3270_set_user_data(this->hSession,(void *) this); setCharSet(lib3270_get_display_charset(this->hSession)); diff --git a/client/src/testprogram/testprogram.cc b/client/src/testprogram/testprogram.cc index 4faa7b3..c6679b7 100644 --- a/client/src/testprogram/testprogram.cc +++ b/client/src/testprogram/testprogram.cc @@ -46,7 +46,7 @@ int main(int argc, char **argv) { - const char * session = "pw3270:a"; + const char * session = ""; // "pw3270:a"; #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant" diff --git a/configure.ac b/configure.ac index 3674bd7..1052463 100644 --- a/configure.ac +++ b/configure.ac @@ -80,7 +80,7 @@ case "$host" in *-mingw32|*-pc-msys) app_cv_osname="windows" CFLAGS="$CFLAGS -D_WIN32_WINNT=0x0600" - LIBS="$LIBS -lws2_32 -lwtsapi32 -lcomdlg32" + LIBS="$LIBS -lws2_32 -lwtsapi32 -lcomdlg32 -lkernel32" LDFLAGS="$LDFLAGS" STATIC_LDFLAGS="-static -static-libgcc -static-libstdc++" DLLEXT=".dll" -- libgit2 0.21.2