diff -r 80bdedb243d7 -r b349c302413c pidgin/win32/winpidgin.c --- a/pidgin/win32/winpidgin.c Sat Nov 23 19:39:07 2024 -0600 +++ b/pidgin/win32/winpidgin.c Sat Nov 23 19:42:35 2024 -0600 @@ -50,7 +50,7 @@ # define PIDGIN_WIN32_UNUSED #endif -typedef int (__cdecl* LPFNPIDGINMAIN)(HINSTANCE, int, char**); +typedef int (__cdecl* LPFNPIDGINMAIN)(int, char**); typedef BOOL (WINAPI* LPFNSETDLLDIRECTORY)(LPCWSTR); typedef BOOL (WINAPI* LPFNATTACHCONSOLE)(DWORD); typedef BOOL (WINAPI* LPFNSETPROCESSDEPPOLICY)(DWORD); @@ -72,90 +72,8 @@ return err_msg; } -#define PIDGIN_WM_PROTOCOL_HANDLE (WM_APP + 14) - -#define PROTO_HANDLER_SWITCH L"--protocolhandler=" - -static void handle_protocol(wchar_t *cmd) { - char *remote_msg, *utf8msg; - wchar_t *tmp1, *tmp2; - int len, wlen; - SIZE_T len_written; - HWND msg_win; - DWORD pid; - HANDLE process; - - /* The start of the message */ - tmp1 = cmd + wcslen(PROTO_HANDLER_SWITCH); - - /* The end of the message */ - if ((tmp2 = wcschr(tmp1, L' '))) - wlen = (tmp2 - tmp1); - else - wlen = wcslen(tmp1); - - if (wlen == 0) { - wprintf(L"No protocol message specified.\n"); - return; - } - - if (!(msg_win = FindWindowExW(NULL, NULL, L"WinpidginMsgWinCls", NULL))) { - wprintf(L"Unable to find an instance of Pidgin to handle protocol message.\n"); - return; - } - - len = WideCharToMultiByte(CP_UTF8, 0, tmp1, - wlen, NULL, 0, NULL, NULL); - if (len) { - utf8msg = malloc(len); - len = WideCharToMultiByte(CP_UTF8, 0, tmp1, - wlen, utf8msg, len, NULL, NULL); - } - - if (len == 0) { - wprintf(L"No protocol message specified.\n"); - return; - } - - GetWindowThreadProcessId(msg_win, &pid); - if (!(process = OpenProcess(PROCESS_VM_OPERATION | PROCESS_VM_WRITE, FALSE, pid))) { - DWORD dw = GetLastError(); - const wchar_t *err_msg = get_win32_error_message(dw); - wprintf(L"Unable to open Pidgin process. (%u) %ls\n", - (UINT)dw, err_msg); - return; - } - - wprintf(L"Trying to handle protocol message:\n'%.*ls'\n", wlen, tmp1); - - /* MEM_COMMIT initializes the memory to zero - * so we don't need to worry that our section of utf8msg isn't nul-terminated */ - if ((remote_msg = (char*) VirtualAllocEx(process, NULL, len + 1, MEM_COMMIT, PAGE_READWRITE))) { - if (WriteProcessMemory(process, remote_msg, utf8msg, len, &len_written)) { - if (!SendMessageA(msg_win, PIDGIN_WM_PROTOCOL_HANDLE, len_written, (LPARAM) remote_msg)) - printf("Unable to send protocol message to Pidgin instance.\n"); - } else { - DWORD dw = GetLastError(); - const wchar_t *err_msg = get_win32_error_message(dw); - wprintf(L"Unable to write to remote memory. (%u) %ls\n", - (UINT)dw, err_msg); - } - - VirtualFreeEx(process, remote_msg, 0, MEM_RELEASE); - } else { - DWORD dw = GetLastError(); - const wchar_t *err_msg = get_win32_error_message(dw); - wprintf(L"Unable to allocate remote memory. (%u) %ls\n", - (UINT)dw, err_msg); - } - - CloseHandle(process); - free(utf8msg); -} - - int __stdcall -WinMain(struct HINSTANCE__ *hInstance, +WinMain(PIDGIN_WIN32_UNUSED struct HINSTANCE__ *hInstance, PIDGIN_WIN32_UNUSED struct HINSTANCE__ *hPrevInstance, PIDGIN_WIN32_UNUSED char *lpszCmdLine, PIDGIN_WIN32_UNUSED int nCmdShow) @@ -165,11 +83,10 @@ wchar_t *pidgin_dir_start = NULL; wchar_t exe_name[MAX_PATH]; HMODULE hmod; - wchar_t *wtmp; int pidgin_argc; char **pidgin_argv; /* This is in utf-8 */ int i, j, k; - BOOL debug = FALSE, help = FALSE, version = FALSE, multiple = FALSE, success; + BOOL debug = FALSE, help = FALSE, version = FALSE, success; LPWSTR *szArglist; LPWSTR cmdLine; @@ -184,8 +101,6 @@ help = TRUE; else if (strstr(__argv[i], "--version") == __argv[i]) version = TRUE; - else if (strstr(__argv[i], "--multiple") == __argv[i]) - multiple = TRUE; } else { if (strchr(__argv[i], 'd')) debug = TRUE; @@ -193,8 +108,6 @@ help = TRUE; if (strchr(__argv[i], 'v')) version = TRUE; - if (strchr(__argv[i], 'm')) - multiple = TRUE; } } } @@ -225,12 +138,6 @@ cmdLine = GetCommandLineW(); - /* If this is a protocol handler invocation, deal with it accordingly */ - if ((wtmp = wcsstr(cmdLine, PROTO_HANDLER_SWITCH)) != NULL) { - handle_protocol(wtmp); - return 0; - } - /* Load exception handler if we have it */ if (GetModuleFileNameW(NULL, pidgin_dir, MAX_PATH) != 0) { @@ -389,6 +296,5 @@ } LocalFree(szArglist); - - return pidgin_main(hInstance, pidgin_argc, pidgin_argv); + return pidgin_main(pidgin_argc, pidgin_argv); }