diff --git a/dlls/dinput/dinput_main.c b/dlls/dinput/dinput_main.c index 45023fc104a..5da60cf1f7c 100644 --- a/dlls/dinput/dinput_main.c +++ b/dlls/dinput/dinput_main.c @@ -1861,6 +1861,7 @@ static BOOL check_hook_thread(void) { static HANDLE hook_thread; HMODULE module; + HANDLE wait_handle = NULL; EnterCriticalSection(&dinput_hook_crit); @@ -1884,11 +1885,17 @@ static BOOL check_hook_thread(void) hook_thread_id = 0; PostThreadMessageW(tid, WM_USER+0x10, 0, 0); - CloseHandle(hook_thread); + wait_handle = hook_thread; hook_thread = NULL; } LeaveCriticalSection(&dinput_hook_crit); + + if (wait_handle) + { + WaitForSingleObject(wait_handle, INFINITE); + CloseHandle(wait_handle); + } return hook_thread_id != 0; }