Rémi Bernon : dinput: Call *_enum_device directly in IDirectInputWImpl_EnumDevices.

Alexandre Julliard julliard at winehq.org
Tue Oct 26 16:19:18 CDT 2021


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

Author: Rémi Bernon <rbernon at codeweavers.com>
Date:   Tue Oct 26 09:17:27 2021 +0200

dinput: Call *_enum_device directly in IDirectInputWImpl_EnumDevices.

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

---

 dlls/dinput/dinput_main.c    | 25 ++++++++++++++-----------
 dlls/dinput/dinput_private.h |  4 ++++
 dlls/dinput/joystick_hid.c   |  3 +--
 dlls/dinput/keyboard.c       |  2 +-
 dlls/dinput/mouse.c          |  2 +-
 5 files changed, 21 insertions(+), 15 deletions(-)

diff --git a/dlls/dinput/dinput_main.c b/dlls/dinput/dinput_main.c
index da790bae36c..27fd7fa7364 100644
--- a/dlls/dinput/dinput_main.c
+++ b/dlls/dinput/dinput_main.c
@@ -324,7 +324,7 @@ static HRESULT WINAPI IDirectInputWImpl_EnumDevices( IDirectInput7W *iface, DWOR
 {
     DIDEVICEINSTANCEW instance = {.dwSize = sizeof(DIDEVICEINSTANCEW)};
     IDirectInputImpl *impl = impl_from_IDirectInput7W( iface );
-    unsigned int i, j;
+    unsigned int i = 0;
     HRESULT hr;
 
     TRACE( "iface %p, type %#x, callback %p, context %p, flags %#x\n", iface, type, callback, context, flags );
@@ -339,19 +339,22 @@ static HRESULT WINAPI IDirectInputWImpl_EnumDevices( IDirectInput7W *iface, DWOR
     if (!impl->initialized)
         return DIERR_NOTINITIALIZED;
 
-    for (i = 0; i < ARRAY_SIZE(dinput_devices); i++)
+    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
     {
-        if (!dinput_devices[i]->enum_device) continue;
-        for (j = 0, hr = S_OK; SUCCEEDED(hr); j++)
-        {
-            TRACE("  - checking device %u ('%s')\n", i, dinput_devices[i]->name);
-            hr = dinput_devices[i]->enum_device( type, flags, &instance, impl->dwVersion, j );
-            if (hr != S_OK) continue;
-            if (enum_callback_wrapper( callback, &instance, context ) == DIENUM_STOP) return S_OK;
-        }
+        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 S_OK;
+    return DI_OK;
 }
 
 static ULONG WINAPI IDirectInputWImpl_AddRef( IDirectInput7W *iface )
diff --git a/dlls/dinput/dinput_private.h b/dlls/dinput/dinput_private.h
index 949e84957d0..553906e705d 100644
--- a/dlls/dinput/dinput_private.h
+++ b/dlls/dinput/dinput_private.h
@@ -59,6 +59,10 @@ struct dinput_device {
     HRESULT (*create_device)(IDirectInputImpl *dinput, REFGUID rguid, IDirectInputDevice8W **out);
 };
 
+extern HRESULT mouse_enum_device( DWORD type, DWORD flags, DIDEVICEINSTANCEW *instance, DWORD version, int index );
+extern HRESULT keyboard_enum_device( DWORD type, DWORD flags, DIDEVICEINSTANCEW *instance, DWORD version, int index );
+extern HRESULT hid_joystick_enum_device( DWORD type, DWORD flags, DIDEVICEINSTANCEW *instance, DWORD version, int index );
+
 struct DevicePlayer {
     GUID instance_guid;
     WCHAR username[MAX_PATH];
diff --git a/dlls/dinput/joystick_hid.c b/dlls/dinput/joystick_hid.c
index 2bd527e7000..8ce55e67ef2 100644
--- a/dlls/dinput/joystick_hid.c
+++ b/dlls/dinput/joystick_hid.c
@@ -1450,8 +1450,7 @@ static HRESULT hid_joystick_device_open( int index, DIDEVICEINSTANCEW *filter, W
     return DI_OK;
 }
 
-static HRESULT hid_joystick_enum_device( DWORD type, DWORD flags, DIDEVICEINSTANCEW *instance,
-                                         DWORD version, int index )
+HRESULT hid_joystick_enum_device( DWORD type, DWORD flags, DIDEVICEINSTANCEW *instance, DWORD version, int index )
 {
     HIDD_ATTRIBUTES attrs = {.Size = sizeof(attrs)};
     PHIDP_PREPARSED_DATA preparsed;
diff --git a/dlls/dinput/keyboard.c b/dlls/dinput/keyboard.c
index 35e55be4f4b..4a3deb161f1 100644
--- a/dlls/dinput/keyboard.c
+++ b/dlls/dinput/keyboard.c
@@ -144,7 +144,7 @@ static DWORD get_keyboard_subtype(void)
     return dev_subtype;
 }
 
-static HRESULT keyboard_enum_device( DWORD type, DWORD flags, DIDEVICEINSTANCEW *instance, DWORD version, int index )
+HRESULT keyboard_enum_device( DWORD type, DWORD flags, DIDEVICEINSTANCEW *instance, DWORD version, int index )
 {
     BYTE subtype = get_keyboard_subtype();
     DWORD size;
diff --git a/dlls/dinput/mouse.c b/dlls/dinput/mouse.c
index d871722e0a9..b120966717e 100644
--- a/dlls/dinput/mouse.c
+++ b/dlls/dinput/mouse.c
@@ -75,7 +75,7 @@ static inline SysMouseImpl *impl_from_IDirectInputDevice8W(IDirectInputDevice8W
     return CONTAINING_RECORD(CONTAINING_RECORD(iface, IDirectInputDeviceImpl, IDirectInputDevice8W_iface), SysMouseImpl, base);
 }
 
-static HRESULT mouse_enum_device( DWORD type, DWORD flags, DIDEVICEINSTANCEW *instance, DWORD version, int index )
+HRESULT mouse_enum_device( DWORD type, DWORD flags, DIDEVICEINSTANCEW *instance, DWORD version, int index )
 {
     DWORD size;
 




More information about the wine-cvs mailing list