From 6e0029f83d8854cf303b9a44bdfc275900034c9a Mon Sep 17 00:00:00 2001 From: Robert Shearman Date: Fri, 20 Jan 2006 16:14:23 +0100 Subject: [PATCH] ole: Fix WM_QUIT Handling in CoWaitForMultipleHandles. When a WM_QUIT message in encountered in CoWaitForMultipleHandles then it should repost the WM_QUIT message and then switch to waiting without checking messages. --- dlls/ole32/compobj.c | 61 ++++++++++++++++++++++++++++---------------- 1 file changed, 39 insertions(+), 22 deletions(-) diff --git a/dlls/ole32/compobj.c b/dlls/ole32/compobj.c index 80ecd11f78e..ed0e4f9363b 100644 --- a/dlls/ole32/compobj.c +++ b/dlls/ole32/compobj.c @@ -2658,9 +2658,8 @@ HRESULT WINAPI CoWaitForMultipleHandles(DWORD dwFlags, DWORD dwTimeout, ULONG cHandles, const HANDLE* pHandles, LPDWORD lpdwindex) { HRESULT hr = S_OK; - DWORD wait_flags = (dwFlags & COWAIT_WAITALL) ? MWMO_WAITALL : 0 | - (dwFlags & COWAIT_ALERTABLE ) ? MWMO_ALERTABLE : 0; DWORD start_time = GetTickCount(); + BOOL message_loop = TRUE; TRACE("(0x%08lx, 0x%08lx, %ld, %p, %p)\n", dwFlags, dwTimeout, cHandles, pHandles, lpdwindex); @@ -2669,37 +2668,56 @@ HRESULT WINAPI CoWaitForMultipleHandles(DWORD dwFlags, DWORD dwTimeout, { DWORD now = GetTickCount(); DWORD res; - + if ((dwTimeout != INFINITE) && (start_time + dwTimeout >= now)) { hr = RPC_S_CALLPENDING; break; } - TRACE("waiting for rpc completion or window message\n"); - - res = MsgWaitForMultipleObjectsEx(cHandles, pHandles, - (dwTimeout == INFINITE) ? INFINITE : start_time + dwTimeout - now, - QS_ALLINPUT, wait_flags); - - if (res == WAIT_OBJECT_0 + cHandles) /* messages available */ + if (message_loop) { - MSG msg; - while (PeekMessageW(&msg, NULL, 0, 0, PM_REMOVE)) + DWORD wait_flags = (dwFlags & COWAIT_WAITALL) ? MWMO_WAITALL : 0 | + (dwFlags & COWAIT_ALERTABLE ) ? MWMO_ALERTABLE : 0; + + TRACE("waiting for rpc completion or window message\n"); + + res = MsgWaitForMultipleObjectsEx(cHandles, pHandles, + (dwTimeout == INFINITE) ? INFINITE : start_time + dwTimeout - now, + QS_ALLINPUT, wait_flags); + + if (res == WAIT_OBJECT_0 + cHandles) /* messages available */ { - /* FIXME: filter the messages here */ - TRACE("received message whilst waiting for RPC: 0x%04x\n", msg.message); - TranslateMessage(&msg); - DispatchMessageW(&msg); - if (msg.message == WM_QUIT) + MSG msg; + while (PeekMessageW(&msg, NULL, 0, 0, PM_REMOVE)) { - TRACE("resending WM_QUIT to outer message loop\n"); - PostQuitMessage(msg.wParam); - goto done; + /* FIXME: filter the messages here */ + TRACE("received message whilst waiting for RPC: 0x%04x\n", msg.message); + TranslateMessage(&msg); + DispatchMessageW(&msg); + if (msg.message == WM_QUIT) + { + TRACE("resending WM_QUIT to outer message loop\n"); + PostQuitMessage(msg.wParam); + /* no longer need to process messages */ + message_loop = FALSE; + break; + } } + continue; } } - else if ((res >= WAIT_OBJECT_0) && (res < WAIT_OBJECT_0 + cHandles)) + else + { + TRACE("waiting for rpc completion\n"); + + res = WaitForMultipleObjectsEx(cHandles, pHandles, + (dwFlags & COWAIT_WAITALL) ? TRUE : FALSE, + (dwTimeout == INFINITE) ? INFINITE : start_time + dwTimeout - now, + (dwFlags & COWAIT_ALERTABLE) ? TRUE : FALSE); + } + + if ((res >= WAIT_OBJECT_0) && (res < WAIT_OBJECT_0 + cHandles)) { /* handle signaled, store index */ *lpdwindex = (res - WAIT_OBJECT_0); @@ -2717,7 +2735,6 @@ HRESULT WINAPI CoWaitForMultipleHandles(DWORD dwFlags, DWORD dwTimeout, break; } } -done: TRACE("-- 0x%08lx\n", hr); return hr; }