win32: Allow WinPidgin to choose to add bin/ DLL directory at runtime

Tue, 22 May 2018 12:43:56 -0500

author
Mike Ruprecht <cmaiku@gmail.com>
date
Tue, 22 May 2018 12:43:56 -0500
changeset 39081
e84ed81142f8
parent 39080
c4bf9f7619f9
child 39082
78ccb5d4e5fe

win32: Allow WinPidgin to choose to add bin/ DLL directory at runtime

This patch changes WinPidgin to add the bin/ DLL directory at runtime
based on whether or not it's already in a bin/ directory. In effect,
this makes it work like
g_win32_get_package_installation_directory_of_module(). The benefit
is that this will allow the win32-dirs option to be removed.

pidgin/win32/winpidgin.c file | annotate | diff | comparison | revisions
--- a/pidgin/win32/winpidgin.c	Tue May 22 10:48:27 2018 -0500
+++ b/pidgin/win32/winpidgin.c	Tue May 22 12:43:56 2018 -0500
@@ -311,12 +311,26 @@
 			pidgin_dir_start[0] = L'\0';
 		}
 
-#ifndef USE_WIN32_FHS
-		/* Add bin/ subdirectory to DLL path */
-		if ((hmod = GetModuleHandleW(L"kernel32.dll"))) {
-			LPFNSETDLLDIRECTORY MySetDllDirectory =
-				(LPFNSETDLLDIRECTORY)
-				GetProcAddress(hmod, "SetDllDirectoryW"); 
+		/* Find parent directory to see if it's bin/ */
+		pidgin_dir_start = wcsrchr(pidgin_dir, L'\\');
+
+		/* Add bin/ subdirectory to DLL path if not already in bin/ */
+		if (pidgin_dir_start == NULL ||
+				wcscmp(pidgin_dir_start + 1, L"bin") != 0) {
+			LPFNSETDLLDIRECTORY MySetDllDirectory = NULL;
+
+			hmod = GetModuleHandleW(L"kernel32.dll");
+
+			if (hmod != NULL) {
+				MySetDllDirectory = (LPFNSETDLLDIRECTORY) GetProcAddress(hmod, "SetDllDirectoryW");
+				if (MySetDllDirectory == NULL) {
+					DWORD dw = GetLastError();
+					const wchar_t *err_msg = get_win32_error_message(dw);
+					wprintf(L"Error loading SetDllDirectory(): (%u) %s\n", dw, err_msg);
+				}
+			} else {
+				printf("Error getting kernel32.dll handle\n");
+			}
 
 			if (MySetDllDirectory) {
 				wcscat(pidgin_dir, L"\\bin");
@@ -328,18 +342,8 @@
 					const wchar_t *err_msg = get_win32_error_message(dw);
 					wprintf(L"Error calling SetDllDirectory(): (%u) %s\n", dw, err_msg);
 				}
-			} else {
-				DWORD dw = GetLastError();
-				const wchar_t *err_msg = get_win32_error_message(dw);
-				wprintf(L"Error loading SetDllDirectory(): (%u) %s\n", dw, err_msg);
 			}
-
-			/* Restore pidgin_dir to point to where the executable is */
-			pidgin_dir_start[0] = L'\0';
-		} else {
-			printf("Error getting kernel32.dll handle\n");
 		}
-#endif
 	} else {
 		DWORD dw = GetLastError();
 		const wchar_t *err_msg = get_win32_error_message(dw);

mercurial