From 3f76a86c13a315a8b657642987935d72f86707c6 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Sat, 12 Mar 2022 15:18:38 +0000 Subject: [PATCH] Windows Pageant: deal with PeekMessageW failing on legacy Windows. This makes Pageant run on Win95 again. Previously (after fixing the startup-time failures due to missing security APIs) it would go into an uninterruptible CPU-consuming spin in the message loop when every attempt to retrieve its messages failed because PeekMessageW doesn't work at all on the 95 series. --- windows/pageant.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/windows/pageant.c b/windows/pageant.c index a08659e5..5ba16801 100644 --- a/windows/pageant.c +++ b/windows/pageant.c @@ -1382,6 +1382,23 @@ static NORETURN void opt_error(const char *fmt, ...) exit(1); } +#ifdef LEGACY_WINDOWS +BOOL sw_PeekMessage(LPMSG msg, HWND hwnd, UINT min, UINT max, UINT remove) +{ + static bool unicode_unavailable = false; + if (!unicode_unavailable) { + BOOL ret = PeekMessageW(msg, hwnd, min, max, remove); + if (!ret && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED) + unicode_unavailable = true; /* don't try again */ + else + return ret; + } + return PeekMessageA(msg, hwnd, min, max, remove); +} +#else +#define sw_PeekMessage PeekMessageW +#endif + int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show) { MSG msg; @@ -1732,7 +1749,7 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show) handle_wait_activate(hwl, n - WAIT_OBJECT_0); handle_wait_list_free(hwl); - while (PeekMessageW(&msg, NULL, 0, 0, PM_REMOVE)) { + while (sw_PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { if (msg.message == WM_QUIT) goto finished; /* two-level break */