comparison pidgin/win32/winpidgin.c @ 30900:3d045343e04d

Use some fully qualified dll locations. There wasn't anything wrong with this as far as I can tell, but since we know specifically where what we're looking for is, this is probably better. Also, plug a small leak and try to find our enchant dll instead of any other one that is in the PATH.
author Daniel Atallah <daniel.atallah@gmail.com>
date Tue, 31 Aug 2010 01:49:53 +0000
parents 140990e07e01
children 2c29fe4757a2
comparison
equal deleted inserted replaced
30899:35d8acf675e9 30900:3d045343e04d
603 int _stdcall 603 int _stdcall
604 WinMain (struct HINSTANCE__ *hInstance, struct HINSTANCE__ *hPrevInstance, 604 WinMain (struct HINSTANCE__ *hInstance, struct HINSTANCE__ *hPrevInstance,
605 char *lpszCmdLine, int nCmdShow) { 605 char *lpszCmdLine, int nCmdShow) {
606 wchar_t errbuf[512]; 606 wchar_t errbuf[512];
607 wchar_t pidgin_dir[MAX_PATH]; 607 wchar_t pidgin_dir[MAX_PATH];
608 wchar_t *pidgin_dir_start = NULL;
608 wchar_t exe_name[MAX_PATH]; 609 wchar_t exe_name[MAX_PATH];
609 HMODULE hmod; 610 HMODULE hmod;
610 wchar_t *tmp;
611 wchar_t *wtmp; 611 wchar_t *wtmp;
612 int pidgin_argc; 612 int pidgin_argc;
613 char **pidgin_argv; /* This is in utf-8 */ 613 char **pidgin_argv; /* This is in utf-8 */
614 int i, j, k; 614 int i, j, k;
615 BOOL debug = FALSE, help = FALSE, version = FALSE, multiple = FALSE, success; 615 BOOL debug = FALSE, help = FALSE, version = FALSE, multiple = FALSE, success;
670 670
671 /* Load exception handler if we have it */ 671 /* Load exception handler if we have it */
672 if (GetModuleFileNameW(NULL, pidgin_dir, MAX_PATH) != 0) { 672 if (GetModuleFileNameW(NULL, pidgin_dir, MAX_PATH) != 0) {
673 673
674 /* primitive dirname() */ 674 /* primitive dirname() */
675 tmp = wcsrchr(pidgin_dir, L'\\'); 675 pidgin_dir_start = wcsrchr(pidgin_dir, L'\\');
676 676
677 if (tmp) { 677 if (pidgin_dir_start) {
678 HMODULE hmod; 678 HMODULE hmod;
679 tmp[0] = L'\0'; 679 pidgin_dir_start[0] = L'\0';
680 680
681 /* tmp++ will now point to the executable file name */ 681 /* tmp++ will now point to the executable file name */
682 wcscpy(exe_name, tmp + 1); 682 wcscpy(exe_name, pidgin_dir_start + 1);
683 683
684 wcscat(pidgin_dir, L"\\exchndl.dll"); 684 wcscat(pidgin_dir, L"\\exchndl.dll");
685 if ((hmod = LoadLibraryW(pidgin_dir))) { 685 if ((hmod = LoadLibraryW(pidgin_dir))) {
686 FARPROC proc; 686 FARPROC proc;
687 /* exchndl.dll is built without UNICODE */ 687 /* exchndl.dll is built without UNICODE */
700 } 700 }
701 } 701 }
702 proc = GetProcAddress(hmod, "SetDebugInfoDir"); 702 proc = GetProcAddress(hmod, "SetDebugInfoDir");
703 if (proc) { 703 if (proc) {
704 char *pidgin_dir_ansi = NULL; 704 char *pidgin_dir_ansi = NULL;
705 tmp[0] = L'\0'; 705 /* Restore pidgin_dir to point to where the executable is */
706 pidgin_dir_start[0] = L'\0';
706 i = WideCharToMultiByte(CP_ACP, 0, pidgin_dir, 707 i = WideCharToMultiByte(CP_ACP, 0, pidgin_dir,
707 -1, NULL, 0, NULL, NULL); 708 -1, NULL, 0, NULL, NULL);
708 if (i != 0) { 709 if (i != 0) {
709 pidgin_dir_ansi = malloc(i * sizeof(char)); 710 pidgin_dir_ansi = malloc(i * sizeof(char));
710 i = WideCharToMultiByte(CP_ACP, 0, pidgin_dir, 711 i = WideCharToMultiByte(CP_ACP, 0, pidgin_dir,
726 } 727 }
727 } 728 }
728 729
729 } 730 }
730 731
731 tmp[0] = L'\0'; 732 /* Restore pidgin_dir to point to where the executable is */
733 pidgin_dir_start[0] = L'\0';
732 } 734 }
733 } else { 735 } else {
734 DWORD dw = GetLastError(); 736 DWORD dw = GetLastError();
735 const wchar_t *err_msg = get_win32_error_message(dw); 737 const wchar_t *err_msg = get_win32_error_message(dw);
736 _snwprintf(errbuf, 512, 738 _snwprintf(errbuf, 512,
761 if (!help && !version) 763 if (!help && !version)
762 if (!winpidgin_set_running(getenv("PIDGIN_MULTI_INST") == NULL && !multiple)) 764 if (!winpidgin_set_running(getenv("PIDGIN_MULTI_INST") == NULL && !multiple))
763 return 0; 765 return 0;
764 766
765 /* Now we are ready for Pidgin .. */ 767 /* Now we are ready for Pidgin .. */
766 if ((hmod = LoadLibraryW(L"pidgin.dll"))) 768 wcscat(pidgin_dir, L"\\pidgin.dll");
769 if ((hmod = LoadLibraryW(pidgin_dir)))
767 pidgin_main = (LPFNPIDGINMAIN) GetProcAddress(hmod, "pidgin_main"); 770 pidgin_main = (LPFNPIDGINMAIN) GetProcAddress(hmod, "pidgin_main");
771
772 /* Restore pidgin_dir to point to where the executable is */
773 if (pidgin_dir_start)
774 pidgin_dir_start[0] = L'\0';
768 775
769 if (!pidgin_main) { 776 if (!pidgin_main) {
770 DWORD dw = GetLastError(); 777 DWORD dw = GetLastError();
771 BOOL mod_not_found = (dw == ERROR_MOD_NOT_FOUND || dw == ERROR_DLL_NOT_FOUND); 778 BOOL mod_not_found = (dw == ERROR_MOD_NOT_FOUND || dw == ERROR_DLL_NOT_FOUND);
772 const wchar_t *err_msg = get_win32_error_message(dw); 779 const wchar_t *err_msg = get_win32_error_message(dw);