| 33 #include <string.h> |
33 #include <string.h> |
| 34 #include <stdio.h> |
34 #include <stdio.h> |
| 35 #include <sys/types.h> |
35 #include <sys/types.h> |
| 36 #include <sys/stat.h> |
36 #include <sys/stat.h> |
| 37 |
37 |
| |
38 #ifndef IS_WIN32_CROSS_COMPILED |
| 38 typedef int (__cdecl* LPFNPIDGINMAIN)(HINSTANCE, int, char**); |
39 typedef int (__cdecl* LPFNPIDGINMAIN)(HINSTANCE, int, char**); |
| |
40 #endif |
| 39 typedef void (WINAPI* LPFNSETDLLDIRECTORY)(LPCWSTR); |
41 typedef void (WINAPI* LPFNSETDLLDIRECTORY)(LPCWSTR); |
| 40 typedef BOOL (WINAPI* LPFNATTACHCONSOLE)(DWORD); |
42 typedef BOOL (WINAPI* LPFNATTACHCONSOLE)(DWORD); |
| 41 typedef BOOL (WINAPI* LPFNSETPROCESSDEPPOLICY)(DWORD); |
43 typedef BOOL (WINAPI* LPFNSETPROCESSDEPPOLICY)(DWORD); |
| 42 |
44 |
| 43 static BOOL portable_mode = FALSE; |
45 static BOOL portable_mode = FALSE; |
| 44 |
46 |
| 45 /* |
47 /* |
| 46 * PROTOTYPES |
48 * PROTOTYPES |
| 47 */ |
49 */ |
| |
50 #ifdef IS_WIN32_CROSS_COMPILED |
| |
51 int __cdecl pidgin_main(HINSTANCE hint, int argc, char *argv[]); |
| |
52 #else |
| 48 static LPFNPIDGINMAIN pidgin_main = NULL; |
53 static LPFNPIDGINMAIN pidgin_main = NULL; |
| |
54 #endif |
| 49 static LPFNSETDLLDIRECTORY MySetDllDirectory = NULL; |
55 static LPFNSETDLLDIRECTORY MySetDllDirectory = NULL; |
| 50 |
56 |
| 51 static const wchar_t *get_win32_error_message(DWORD err) { |
57 static const wchar_t *get_win32_error_message(DWORD err) { |
| 52 static wchar_t err_msg[512]; |
58 static wchar_t err_msg[512]; |
| 53 |
59 |
| 869 /* If help, version or multiple flag used, do not check Mutex */ |
875 /* If help, version or multiple flag used, do not check Mutex */ |
| 870 if (!help && !version) |
876 if (!help && !version) |
| 871 if (!winpidgin_set_running(getenv("PIDGIN_MULTI_INST") == NULL && !multiple)) |
877 if (!winpidgin_set_running(getenv("PIDGIN_MULTI_INST") == NULL && !multiple)) |
| 872 return 0; |
878 return 0; |
| 873 |
879 |
| |
880 #ifndef IS_WIN32_CROSS_COMPILED |
| 874 /* Now we are ready for Pidgin .. */ |
881 /* Now we are ready for Pidgin .. */ |
| 875 wcscat(pidgin_dir, L"\\pidgin.dll"); |
882 wcscat(pidgin_dir, L"\\pidgin.dll"); |
| 876 if ((hmod = LoadLibraryW(pidgin_dir))) |
883 if ((hmod = LoadLibraryW(pidgin_dir))) |
| 877 pidgin_main = (LPFNPIDGINMAIN) GetProcAddress(hmod, "pidgin_main"); |
884 pidgin_main = (LPFNPIDGINMAIN) GetProcAddress(hmod, "pidgin_main"); |
| |
885 #endif |
| 878 |
886 |
| 879 /* Restore pidgin_dir to point to where the executable is */ |
887 /* Restore pidgin_dir to point to where the executable is */ |
| 880 if (pidgin_dir_start) |
888 if (pidgin_dir_start) |
| 881 pidgin_dir_start[0] = L'\0'; |
889 pidgin_dir_start[0] = L'\0'; |
| 882 |
890 |
| |
891 #ifndef IS_WIN32_CROSS_COMPILED |
| 883 if (!pidgin_main) { |
892 if (!pidgin_main) { |
| 884 DWORD dw = GetLastError(); |
893 DWORD dw = GetLastError(); |
| 885 BOOL mod_not_found = (dw == ERROR_MOD_NOT_FOUND || dw == ERROR_DLL_NOT_FOUND); |
894 BOOL mod_not_found = (dw == ERROR_MOD_NOT_FOUND || dw == ERROR_DLL_NOT_FOUND); |
| 886 const wchar_t *err_msg = get_win32_error_message(dw); |
895 const wchar_t *err_msg = get_win32_error_message(dw); |
| 887 |
896 |
| 892 wprintf(L"%s\n", errbuf); |
901 wprintf(L"%s\n", errbuf); |
| 893 MessageBoxW(NULL, errbuf, L"Error", MB_OK | MB_TOPMOST); |
902 MessageBoxW(NULL, errbuf, L"Error", MB_OK | MB_TOPMOST); |
| 894 |
903 |
| 895 return 0; |
904 return 0; |
| 896 } |
905 } |
| |
906 #endif |
| 897 |
907 |
| 898 /* Convert argv to utf-8*/ |
908 /* Convert argv to utf-8*/ |
| 899 szArglist = CommandLineToArgvW(cmdLine, &j); |
909 szArglist = CommandLineToArgvW(cmdLine, &j); |
| 900 pidgin_argc = j; |
910 pidgin_argc = j; |
| 901 pidgin_argv = malloc(pidgin_argc* sizeof(char*)); |
911 pidgin_argv = malloc(pidgin_argc* sizeof(char*)); |