comparison src/win_gaim.c @ 10688:7818a5e9e3a2

[gaim-migrate @ 12237] Fixed a problem which would make gaim unable to use GTK installations that it should be able to use. The DllPath registry entry was never being read because the target buffer size was being incorrectly specified. Unless you had the Installer registry key specified and set to NSIS, it would point to the wrong directory for GTK dlls. The error messages from failed registry lookups are now better. I also removed some code that was intended to support alternate GTK installations (dropline?) that use the \lib directory instead of the \bin for the gtk+ dlls, it really isn't an issue anymore. committer: Tailor Script <tailor@pidgin.im>
author Daniel Atallah <daniel.atallah@gmail.com>
date Sat, 12 Mar 2005 19:35:37 +0000
parents db44efdf6565
children cfacc0de0d94
comparison
equal deleted inserted replaced
10687:b256ce6b85b8 10688:7818a5e9e3a2
39 static LPFNGAIMMAIN gaim_main = NULL; 39 static LPFNGAIMMAIN gaim_main = NULL;
40 static LPFNSETDLLDIRECTORY MySetDllDirectory = NULL; 40 static LPFNSETDLLDIRECTORY MySetDllDirectory = NULL;
41 41
42 42
43 static BOOL read_reg_string(HKEY key, char* sub_key, char* val_name, LPBYTE data, LPDWORD data_len) { 43 static BOOL read_reg_string(HKEY key, char* sub_key, char* val_name, LPBYTE data, LPDWORD data_len) {
44 HKEY hkey; 44 HKEY hkey;
45 BOOL ret = FALSE; 45 BOOL ret = FALSE;
46 int retv; 46 LONG retv;
47 47
48 if(ERROR_SUCCESS == RegOpenKeyEx(key, 48 if (ERROR_SUCCESS == (retv = RegOpenKeyEx(key, sub_key, 0,
49 sub_key, 49 KEY_QUERY_VALUE, &hkey))) {
50 0, KEY_QUERY_VALUE, &hkey)) { 50 if (ERROR_SUCCESS == (retv = RegQueryValueEx(hkey, val_name,
51 if(ERROR_SUCCESS == (retv=RegQueryValueEx(hkey, val_name, 0, NULL, data, data_len))) 51 NULL, NULL, data, data_len)))
52 ret = TRUE; 52 ret = TRUE;
53 else 53 else {
54 printf("Could not read reg key '%s' subkey '%s' value: '%s'\nError: %u\n", 54 TCHAR szBuf[80];
55 ((key == HKEY_LOCAL_MACHINE) ? "HKLM" : (key == HKEY_CURRENT_USER) ? "HKCU" : "???"), 55
56 sub_key, val_name, (UINT)GetLastError()); 56 FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,
57 RegCloseKey(key); 57 NULL, retv, 0,
58 } 58 (LPTSTR) &szBuf, sizeof(szBuf), NULL);
59 else 59
60 printf("Could not open reg subkey: %s\nError: %u\n", sub_key, (UINT)GetLastError()); 60 printf("Could not read reg key '%s' subkey '%s' value: '%s'\nError: (%ld) %s\n",
61 ((key == HKEY_LOCAL_MACHINE) ? "HKLM" :
62 (key == HKEY_CURRENT_USER) ? "HKCU" :
63 "???"),
64 sub_key, val_name, retv, szBuf);
65 }
66 RegCloseKey(key);
67 }
68 else {
69 TCHAR szBuf[80];
70
71 FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, retv, 0,
72 (LPTSTR) &szBuf, sizeof(szBuf), NULL);
73 printf("Could not open reg subkey: %s\nError: (%ld) %s\n",
74 sub_key, retv, szBuf);
75 }
61 76
62 return ret; 77 return ret;
63 } 78 }
64 79
65 static void dll_prep() { 80 static void dll_prep() {
66 char gtkpath[MAX_PATH]; 81 char gtkpath[MAX_PATH + 1];
67 char path[MAX_PATH]; 82 char path[MAX_PATH + 1];
68 DWORD plen = MAX_PATH; 83 DWORD plen;
69 int gotreg=FALSE; 84 BOOL gotreg = FALSE;
70 HKEY hkey; 85 HKEY hkey;
71 HMODULE hmod; 86 HMODULE hmod;
72 87
88 plen = sizeof(gtkpath);
73 if(!(gotreg = read_reg_string((hkey=HKEY_LOCAL_MACHINE), "SOFTWARE\\GTK\\2.0", "Path", (LPBYTE)&gtkpath, &plen))) 89 if(!(gotreg = read_reg_string((hkey=HKEY_LOCAL_MACHINE), "SOFTWARE\\GTK\\2.0", "Path", (LPBYTE)&gtkpath, &plen)))
74 gotreg = read_reg_string((hkey=HKEY_CURRENT_USER), "SOFTWARE\\GTK\\2.0", "Path", (LPBYTE)&gtkpath, &plen); 90 gotreg = read_reg_string((hkey=HKEY_CURRENT_USER), "SOFTWARE\\GTK\\2.0", "Path", (LPBYTE)&gtkpath, &plen);
75 91
76 if(!gotreg) 92 if(!gotreg)
77 return; 93 return;
78 94
79 /* Determine GTK+ dll path .. */ 95 /* this value is replaced during a successful RegQueryValueEx() */
80 if(!read_reg_string(hkey, "SOFTWARE\\GTK\\2.0", "DllPath", (LPBYTE)&path, &plen)) { 96 plen = sizeof(path);
81 char version[10]; 97 /* Determine GTK+ dll path .. */
82 char inst[10]; 98 if (!read_reg_string(hkey, "SOFTWARE\\GTK\\2.0", "DllPath",
83 DWORD len = 10; 99 (LPBYTE) &path, &plen)) {
84 100 strcpy(path, gtkpath);
85 strcpy(path, gtkpath); 101 strcat(path, "\\bin");
86 if(read_reg_string(hkey, "SOFTWARE\\GTK\\2.0", "Version", (LPBYTE)&version, &len) && 102 }
87 read_reg_string(hkey, "SOFTWARE\\GTK\\2.0", "Installer", (LPBYTE)&inst, &len)) {
88 if(strcmp(version, "2.2.2") >= 0 &&
89 strcmp(inst, "NSIS") == 0) {
90 strcat(path, "\\bin");
91 }
92 else
93 strcat(path, "\\lib");
94 }
95 else
96 strcat(path, "\\lib");
97 }
98 103
99 printf("GTK+ path found: %s\n", path); 104 printf("GTK+ path found: %s\n", path);
100 105
101 if((hmod=GetModuleHandle("kernel32.dll"))) { 106 if((hmod=GetModuleHandle("kernel32.dll"))) {
102 MySetDllDirectory = (LPFNSETDLLDIRECTORY)GetProcAddress(hmod, "SetDllDirectory"); 107 MySetDllDirectory = (LPFNSETDLLDIRECTORY)GetProcAddress(hmod, "SetDllDirectory");