Rémi Bernon : dinput: Implement IDirectInput_EnumDevices with IDirectInput8_EnumDevices.

Alexandre Julliard julliard at winehq.org
Tue Nov 16 16:32:26 CST 2021


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

Author: Rémi Bernon <rbernon at codeweavers.com>
Date:   Tue Nov 16 08:23:39 2021 +0100

dinput: Implement IDirectInput_EnumDevices with IDirectInput8_EnumDevices.

Instead of the other way around.

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

---

 dlls/dinput/dinput_main.c | 66 ++++++++++++++++++++++++++---------------------
 dlls/dinput8/tests/hid.c  |  2 --
 2 files changed, 37 insertions(+), 31 deletions(-)

diff --git a/dlls/dinput/dinput_main.c b/dlls/dinput/dinput_main.c
index 835a8656bd1..f53a1b502e9 100644
--- a/dlls/dinput/dinput_main.c
+++ b/dlls/dinput/dinput_main.c
@@ -315,39 +315,17 @@ __ASM_GLOBAL_FUNC( enum_callback_wrapper,
 static HRESULT WINAPI IDirectInputWImpl_EnumDevices( IDirectInput7W *iface, DWORD type, LPDIENUMDEVICESCALLBACKW callback,
                                                      void *context, DWORD flags )
 {
-    DIDEVICEINSTANCEW instance = {.dwSize = sizeof(DIDEVICEINSTANCEW)};
     IDirectInputImpl *impl = impl_from_IDirectInput7W( iface );
-    unsigned int i = 0;
-    HRESULT hr;
 
     TRACE( "iface %p, type %#x, callback %p, context %p, flags %#x\n", iface, type, callback, context, flags );
 
     if (!callback) return DIERR_INVALIDPARAM;
 
-    if ((type > DI8DEVCLASS_GAMECTRL && type < DI8DEVTYPE_DEVICE) || type > DI8DEVTYPE_SUPPLEMENTAL)
+    if (type > DIDEVTYPE_JOYSTICK) return DIERR_INVALIDPARAM;
+    if (flags & ~(DIEDFL_ATTACHEDONLY | DIEDFL_FORCEFEEDBACK | DIEDFL_INCLUDEALIASES | DIEDFL_INCLUDEPHANTOMS))
         return DIERR_INVALIDPARAM;
-    if (flags & ~(DIEDFL_ATTACHEDONLY|DIEDFL_FORCEFEEDBACK|DIEDFL_INCLUDEALIASES|DIEDFL_INCLUDEPHANTOMS|DIEDFL_INCLUDEHIDDEN))
-        return DIERR_INVALIDPARAM;
-
-    if (!impl->initialized)
-        return DIERR_NOTINITIALIZED;
-
-    hr = mouse_enum_device( type, flags, &instance, impl->dwVersion, 0 );
-    if (hr == DI_OK && enum_callback_wrapper( callback, &instance, context ) == DIENUM_STOP)
-        return DI_OK;
-    hr = keyboard_enum_device( type, flags, &instance, impl->dwVersion, 0 );
-    if (hr == DI_OK && enum_callback_wrapper( callback, &instance, context ) == DIENUM_STOP)
-        return DI_OK;
 
-    do
-    {
-        hr = hid_joystick_enum_device( type, flags, &instance, impl->dwVersion, i++ );
-        if (hr == DI_OK && enum_callback_wrapper( callback, &instance, context ) == DIENUM_STOP)
-            return DI_OK;
-    }
-    while (SUCCEEDED(hr));
-
-    return DI_OK;
+    return IDirectInput8_EnumDevices( &impl->IDirectInput8W_iface, type, callback, context, flags );
 }
 
 static ULONG WINAPI IDirectInputWImpl_AddRef( IDirectInput7W *iface )
@@ -659,11 +637,41 @@ static HRESULT WINAPI IDirectInput8WImpl_CreateDevice(LPDIRECTINPUT8W iface, REF
     return IDirectInput7_CreateDeviceEx( &This->IDirectInput7W_iface, rguid, &IID_IDirectInputDevice8W, (LPVOID *)pdev, punk );
 }
 
-static HRESULT WINAPI IDirectInput8WImpl_EnumDevices(LPDIRECTINPUT8W iface, DWORD dwDevType, LPDIENUMDEVICESCALLBACKW lpCallback,
-                                                     LPVOID pvRef, DWORD dwFlags)
+static HRESULT WINAPI IDirectInput8WImpl_EnumDevices( IDirectInput8W *iface, DWORD type, LPDIENUMDEVICESCALLBACKW callback,
+                                                      void *context, DWORD flags )
 {
-    IDirectInputImpl *This = impl_from_IDirectInput8W( iface );
-    return IDirectInput_EnumDevices( &This->IDirectInput7W_iface, dwDevType, lpCallback, pvRef, dwFlags );
+    DIDEVICEINSTANCEW instance = {.dwSize = sizeof(DIDEVICEINSTANCEW)};
+    IDirectInputImpl *impl = impl_from_IDirectInput8W( iface );
+    unsigned int i = 0;
+    HRESULT hr;
+
+    TRACE( "iface %p, type %#x, callback %p, context %p, flags %#x\n", iface, type, callback, context, flags );
+
+    if (!callback) return DIERR_INVALIDPARAM;
+
+    if ((type > DI8DEVCLASS_GAMECTRL && type < DI8DEVTYPE_DEVICE) || type > DI8DEVTYPE_SUPPLEMENTAL)
+        return DIERR_INVALIDPARAM;
+    if (flags & ~(DIEDFL_ATTACHEDONLY | DIEDFL_FORCEFEEDBACK | DIEDFL_INCLUDEALIASES |
+                  DIEDFL_INCLUDEPHANTOMS | DIEDFL_INCLUDEHIDDEN))
+        return DIERR_INVALIDPARAM;
+
+    if (!impl->initialized) return DIERR_NOTINITIALIZED;
+
+    hr = mouse_enum_device( type, flags, &instance, impl->dwVersion, 0 );
+    if (hr == DI_OK && enum_callback_wrapper( callback, &instance, context ) == DIENUM_STOP)
+        return DI_OK;
+    hr = keyboard_enum_device( type, flags, &instance, impl->dwVersion, 0 );
+    if (hr == DI_OK && enum_callback_wrapper( callback, &instance, context ) == DIENUM_STOP)
+        return DI_OK;
+
+    do
+    {
+        hr = hid_joystick_enum_device( type, flags, &instance, impl->dwVersion, i++ );
+        if (hr == DI_OK && enum_callback_wrapper( callback, &instance, context ) == DIENUM_STOP)
+            return DI_OK;
+    } while (SUCCEEDED(hr));
+
+    return DI_OK;
 }
 
 static HRESULT WINAPI IDirectInput8WImpl_GetDeviceStatus(LPDIRECTINPUT8W iface, REFGUID rguid)
diff --git a/dlls/dinput8/tests/hid.c b/dlls/dinput8/tests/hid.c
index 3c8492842e4..73f8ea33650 100644
--- a/dlls/dinput8/tests/hid.c
+++ b/dlls/dinput8/tests/hid.c
@@ -3600,7 +3600,6 @@ static HRESULT create_dinput_device( DWORD version, DIDEVICEINSTANCEW *devinst,
         hr = IDirectInput_EnumDevices( di, 0xdeadbeef, enum_device_count, &count, DIEDFL_ALLDEVICES );
         ok( hr == DIERR_INVALIDPARAM, "EnumDevices returned: %#x\n", hr );
         hr = IDirectInput_EnumDevices( di, 0, enum_device_count, &count, DIEDFL_INCLUDEHIDDEN );
-        todo_wine
         ok( hr == DIERR_INVALIDPARAM, "EnumDevices returned: %#x\n", hr );
 
         count = 0;
@@ -3641,7 +3640,6 @@ static HRESULT create_dinput_device( DWORD version, DIDEVICEINSTANCEW *devinst,
         else ok( count == 1, "got count %u, expected 1\n", count );
 
         hr = IDirectInput_EnumDevices( di, 0x14, enum_device_count, &count, DIEDFL_ALLDEVICES );
-        todo_wine
         ok( hr == DIERR_INVALIDPARAM, "EnumDevices returned: %#x\n", hr );
 
         hr = IDirectInput_CreateDevice( di, &expect_guid_product, (IDirectInputDeviceW **)device, NULL );




More information about the wine-cvs mailing list