Skip to content

Commit

Permalink
Fix "GetMessage" implementation potentially removing "WM_QUIT" messages
Browse files Browse the repository at this point in the history
  • Loading branch information
crosire committed May 30, 2021
1 parent 9bf2dc2 commit 8aed4b0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion source/dll_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -956,7 +956,7 @@ BOOL APIENTRY DllMain(HMODULE hModule, DWORD fdwReason, LPVOID)
g_module_handle = nullptr;
// This duration has to be slightly larger than the timeout in 'HookGetMessage' to ensure success
// It should also be large enough to cover any potential other calls to previous hooks that may still be in flight from other threads
Sleep(1050);
Sleep(1000);

# ifndef NDEBUG
RemoveVectoredExceptionHandler(g_exception_handler_handle);
Expand Down
8 changes: 4 additions & 4 deletions source/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -481,9 +481,9 @@ HOOK_EXPORT BOOL WINAPI HookGetMessageA(LPMSG lpMsg, HWND hWnd, UINT wMsgFilterM
#if 1
// Implement 'GetMessage' with a timeout (see also DLL_PROCESS_DETACH in dllmain.cpp for more explanation)
while (!PeekMessageA(lpMsg, hWnd, wMsgFilterMin, wMsgFilterMax, PM_REMOVE) && g_module_handle != nullptr)
MsgWaitForMultipleObjects(0, nullptr, FALSE, 1000, QS_ALLINPUT);
MsgWaitForMultipleObjects(0, nullptr, FALSE, 500, QS_ALLINPUT);

if (g_module_handle == nullptr)
if (g_module_handle == nullptr && lpMsg->message != WM_QUIT)
std::memset(lpMsg, 0, sizeof(MSG)); // Clear message structure, so application does not process it
#else
static const auto trampoline = reshade::hooks::call(HookGetMessageA);
Expand All @@ -509,9 +509,9 @@ HOOK_EXPORT BOOL WINAPI HookGetMessageW(LPMSG lpMsg, HWND hWnd, UINT wMsgFilterM
{
#if 1
while (!PeekMessageW(lpMsg, hWnd, wMsgFilterMin, wMsgFilterMax, PM_REMOVE) && g_module_handle != nullptr)
MsgWaitForMultipleObjects(0, nullptr, FALSE, 1000, QS_ALLINPUT);
MsgWaitForMultipleObjects(0, nullptr, FALSE, 500, QS_ALLINPUT);

if (g_module_handle == nullptr)
if (g_module_handle == nullptr && lpMsg->message != WM_QUIT)
std::memset(lpMsg, 0, sizeof(MSG));
#else
static const auto trampoline = reshade::hooks::call(HookGetMessageW);
Expand Down

0 comments on commit 8aed4b0

Please sign in to comment.