Rémi Bernon : dinput: Check acquired state in IDirectInputDevice2WImpl_SetCooperativeLevel.

Alexandre Julliard julliard at winehq.org
Thu Sep 23 15:35:04 CDT 2021


Module: wine
Branch: master
Commit: 0686815ff621479f7c53f3318cd08f0b0d837172
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=0686815ff621479f7c53f3318cd08f0b0d837172

Author: Rémi Bernon <rbernon at codeweavers.com>
Date:   Thu Sep 23 10:51:35 2021 +0200

dinput: Check acquired state in IDirectInputDevice2WImpl_SetCooperativeLevel.

Signed-off-by: Rémi Bernon <rbernon at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/dinput/device.c     | 12 +++++++++---
 dlls/dinput8/tests/hid.c |  1 -
 2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/dlls/dinput/device.c b/dlls/dinput/device.c
index 2a3ed391919..11496640049 100644
--- a/dlls/dinput/device.c
+++ b/dlls/dinput/device.c
@@ -1118,6 +1118,7 @@ HRESULT WINAPI IDirectInputDevice2WImpl_SetDataFormat(LPDIRECTINPUTDEVICE8W ifac
 HRESULT WINAPI IDirectInputDevice2WImpl_SetCooperativeLevel(LPDIRECTINPUTDEVICE8W iface, HWND hwnd, DWORD dwflags)
 {
     IDirectInputDeviceImpl *This = impl_from_IDirectInputDevice8W(iface);
+    HRESULT hr;
 
     TRACE("(%p) %p,0x%08x\n", This, hwnd, dwflags);
     _dump_cooperativelevel_DI(dwflags);
@@ -1144,11 +1145,16 @@ HRESULT WINAPI IDirectInputDevice2WImpl_SetCooperativeLevel(LPDIRECTINPUTDEVICE8
 
     /* Store the window which asks for the mouse */
     EnterCriticalSection(&This->crit);
-    This->win = hwnd;
-    This->dwCoopLevel = dwflags;
+    if (This->acquired) hr = DIERR_ACQUIRED;
+    else
+    {
+        This->win = hwnd;
+        This->dwCoopLevel = dwflags;
+        hr = DI_OK;
+    }
     LeaveCriticalSection(&This->crit);
 
-    return DI_OK;
+    return hr;
 }
 
 /******************************************************************************
diff --git a/dlls/dinput8/tests/hid.c b/dlls/dinput8/tests/hid.c
index e017e048a30..c0f1b78160c 100644
--- a/dlls/dinput8/tests/hid.c
+++ b/dlls/dinput8/tests/hid.c
@@ -4082,7 +4082,6 @@ static void test_simple_joystick(void)
     hr = IDirectInputDevice8_Acquire( device );
     ok( hr == DI_OK, "IDirectInputDevice8_Acquire returned: %#x\n", hr );
     hr = IDirectInputDevice8_SetCooperativeLevel( device, hwnd, DISCL_FOREGROUND | DISCL_EXCLUSIVE );
-    todo_wine
     ok( hr == DIERR_ACQUIRED, "IDirectInputDevice8_SetCooperativeLevel returned: %#x\n", hr );
     hr = IDirectInputDevice8_Unacquire( device );
     ok( hr == DI_OK, "IDirectInputDevice8_Unacquire returned: %#x\n", hr );




More information about the wine-cvs mailing list