dinput: Fail in SetCooperativeLevel on invalid hwnd.

Bernhard Übelacker bernhardu at vr-web.de
Tue Nov 24 14:25:58 CST 2015


https://bugs.winehq.org/show_bug.cgi?id=39665

MotoGP 3 demo fails to accept key presses to control the driver.
The game calls SetCooperativeLevel twice. First with an invalid hwnd
(but not NULL) and later with the real hwnd.
Unfortunately the first call succeeded and saved the invalid one
in the device.
Both calls with flag DISCL_FOREGROUND.

Later calls to Acquire are failing because saved (invalid) hwnd is not
the foreground window.

trace:dinput:IDirectInputDevice2WImpl_SetCooperativeLevel (0x1a63d00) 0x400000,0x00000005
trace:dinput:IDirectInputDevice2WImpl_SetCooperativeLevel (0x1a66218) 0x10072,0x00000016

Signed-off-by: Bernhard Übelacker <bernhardu at vr-web.de>
---
 dlls/dinput/device.c         |  4 ++--
 dlls/dinput/tests/keyboard.c | 11 +++++++++++
 2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/dlls/dinput/device.c b/dlls/dinput/device.c
index 1ba6ffc..e525f01 100644
--- a/dlls/dinput/device.c
+++ b/dlls/dinput/device.c
@@ -1028,10 +1028,10 @@ HRESULT WINAPI IDirectInputDevice2WImpl_SetCooperativeLevel(LPDIRECTINPUTDEVICE8
 
     if (hwnd && GetWindowLongW(hwnd, GWL_STYLE) & WS_CHILD) return E_HANDLE;
 
-    if (dwflags == (DISCL_NONEXCLUSIVE | DISCL_BACKGROUND))
+    if (!hwnd && dwflags == (DISCL_NONEXCLUSIVE | DISCL_BACKGROUND))
         hwnd = GetDesktopWindow();
 
-    if (!hwnd) return E_HANDLE;
+    if (!IsWindow(hwnd)) return E_HANDLE;
 
     /* For security reasons native does not allow exclusive background level
        for mouse and keyboard only */
diff --git a/dlls/dinput/tests/keyboard.c b/dlls/dinput/tests/keyboard.c
index 520740d..e51e332 100644
--- a/dlls/dinput/tests/keyboard.c
+++ b/dlls/dinput/tests/keyboard.c
@@ -121,6 +121,12 @@ static const HRESULT SetCoop_null_window[16] =  {
     E_INVALIDARG, E_HANDLE,     S_OK,         E_INVALIDARG,
     E_INVALIDARG, E_INVALIDARG, E_INVALIDARG, E_INVALIDARG};
 
+static const HRESULT SetCoop_invalid_window[16] =  {
+    E_INVALIDARG, E_INVALIDARG, E_INVALIDARG, E_INVALIDARG,
+    E_INVALIDARG, E_HANDLE,     E_HANDLE,     E_INVALIDARG,
+    E_INVALIDARG, E_HANDLE,     E_HANDLE,     E_INVALIDARG,
+    E_INVALIDARG, E_INVALIDARG, E_INVALIDARG, E_INVALIDARG};
+
 static const HRESULT SetCoop_real_window[16] =  {
     E_INVALIDARG, E_INVALIDARG, E_INVALIDARG, E_INVALIDARG,
     E_INVALIDARG, S_OK,         S_OK,         E_INVALIDARG,
@@ -151,6 +157,11 @@ static void test_set_coop(IDirectInputA *pDI, HWND hwnd)
     }
     for (i=0; i<16; i++)
     {
+        hr = IDirectInputDevice_SetCooperativeLevel(pKeyboard, (HWND)0x400000, i);
+        ok(hr == SetCoop_invalid_window[i], "SetCooperativeLevel(invalid, %d): %08x\n", i, hr);
+    }
+    for (i=0; i<16; i++)
+    {
         hr = IDirectInputDevice_SetCooperativeLevel(pKeyboard, hwnd, i);
         ok(hr == SetCoop_real_window[i], "SetCooperativeLevel(hwnd, %d): %08x\n", i, hr);
     }
-- 
2.1.4




More information about the wine-patches mailing list