Rémi Bernon : windows.gaming.input: Acquire the device exclusively when creating ForceFeedbackMotor.

Alexandre Julliard julliard at winehq.org
Mon Apr 25 16:30:33 CDT 2022


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

Author: Rémi Bernon <rbernon at codeweavers.com>
Date:   Mon Apr 25 14:56:18 2022 +0200

windows.gaming.input: Acquire the device exclusively when creating ForceFeedbackMotor.

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

---

 dlls/dinput/tests/force_feedback.c         |  4 +---
 dlls/windows.gaming.input/force_feedback.c | 11 +++++++++++
 2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/dlls/dinput/tests/force_feedback.c b/dlls/dinput/tests/force_feedback.c
index c298206eb20..9c9af8b6389 100644
--- a/dlls/dinput/tests/force_feedback.c
+++ b/dlls/dinput/tests/force_feedback.c
@@ -5048,7 +5048,6 @@ static void test_windows_gaming_input(void)
             .report_id = 1,
             .report_len = 2,
             .report_buf = {1, 0x01},
-            .todo = TRUE,
         },
         /* device gain */
         {
@@ -5056,7 +5055,6 @@ static void test_windows_gaming_input(void)
             .report_id = 6,
             .report_len = 2,
             .report_buf = {6, 0xff},
-            .todo = TRUE,
         },
     };
     static struct hid_expect expect_set_gain =
@@ -5284,7 +5282,7 @@ static void test_windows_gaming_input(void)
     set_hid_expect( file, expect_acquire, sizeof(expect_acquire) );
     hr = IRawGameController_get_ForceFeedbackMotors( raw_controller, &motors_view );
     ok( hr == S_OK, "get_ForceFeedbackMotors returned %#lx\n", hr );
-    wait_hid_expect_( __FILE__, __LINE__, file, 100, TRUE ); /* device gain reports are written asynchronously */
+    wait_hid_expect( file, 100 ); /* device gain reports are written asynchronously */
 
     hr = IVectorView_ForceFeedbackMotor_get_Size( motors_view, &size );
     ok( hr == S_OK, "get_Size returned %#lx\n", hr );
diff --git a/dlls/windows.gaming.input/force_feedback.c b/dlls/windows.gaming.input/force_feedback.c
index 24617d16733..54742475e7b 100644
--- a/dlls/windows.gaming.input/force_feedback.c
+++ b/dlls/windows.gaming.input/force_feedback.c
@@ -211,9 +211,14 @@ static const struct IForceFeedbackMotorVtbl motor_vtbl =
 HRESULT force_feedback_motor_create( IDirectInputDevice8W *device, IForceFeedbackMotor **out )
 {
     struct motor *impl;
+    HRESULT hr;
 
     TRACE( "device %p, out %p\n", device, out );
 
+    if (FAILED(hr = IDirectInputDevice8_Unacquire( device ))) goto failed;
+    if (FAILED(hr = IDirectInputDevice8_SetCooperativeLevel( device, GetDesktopWindow(), DISCL_BACKGROUND | DISCL_EXCLUSIVE ))) goto failed;
+    if (FAILED(hr = IDirectInputDevice8_Acquire( device ))) goto failed;
+
     if (!(impl = calloc( 1, sizeof(*impl) ))) return E_OUTOFMEMORY;
     impl->IForceFeedbackMotor_iface.lpVtbl = &motor_vtbl;
     impl->ref = 1;
@@ -224,4 +229,10 @@ HRESULT force_feedback_motor_create( IDirectInputDevice8W *device, IForceFeedbac
     *out = &impl->IForceFeedbackMotor_iface;
     TRACE( "created ForceFeedbackMotor %p\n", *out );
     return S_OK;
+
+failed:
+    IDirectInputDevice8_SetCooperativeLevel( device, 0, DISCL_BACKGROUND | DISCL_NONEXCLUSIVE );
+    IDirectInputDevice8_Acquire( device );
+    WARN( "Failed to acquire device exclusively, hr %#lx\n", hr );
+    return hr;
 }




More information about the wine-cvs mailing list