[PATCH 2/2] dinput: Pass a single GUID pointer to hid_joystick_device_open().
Zebediah Figura
zfigura at codeweavers.com
Mon May 16 21:52:57 CDT 2022
We set the instance and product IDs for all joysticks to match the latter parts
of hid_joystick_guid and dinput_pidvid_guid, respectively. Therefore there is no
need to manually check which one we are matching against.
Signed-off-by: Zebediah Figura <zfigura at codeweavers.com>
---
dlls/dinput/joystick_hid.c | 51 +++++++++++---------------------------
1 file changed, 14 insertions(+), 37 deletions(-)
diff --git a/dlls/dinput/joystick_hid.c b/dlls/dinput/joystick_hid.c
index e54d50f8bfa..f9f34d0e5e3 100644
--- a/dlls/dinput/joystick_hid.c
+++ b/dlls/dinput/joystick_hid.c
@@ -1564,15 +1564,14 @@ failed:
return DIERR_DEVICENOTREG;
}
-static HRESULT hid_joystick_device_open( int index, DIDEVICEINSTANCEW *filter, WCHAR *device_path,
- HANDLE *device, PHIDP_PREPARSED_DATA *preparsed,
+static HRESULT hid_joystick_device_open( int index, const GUID *guid, DIDEVICEINSTANCEW *instance,
+ WCHAR *device_path, HANDLE *device, PHIDP_PREPARSED_DATA *preparsed,
HIDD_ATTRIBUTES *attrs, HIDP_CAPS *caps, DWORD version )
{
char buffer[sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_W) + MAX_PATH * sizeof(WCHAR)];
SP_DEVICE_INTERFACE_DETAIL_DATA_W *detail = (void *)buffer;
SP_DEVICE_INTERFACE_DATA iface = {.cbSize = sizeof(iface)};
SP_DEVINFO_DATA devinfo = {.cbSize = sizeof(devinfo)};
- DIDEVICEINSTANCEW instance = *filter;
WCHAR device_id[MAX_PATH], *tmp;
HDEVINFO set, xi_set;
UINT32 i = 0, handle;
@@ -1580,8 +1579,7 @@ static HRESULT hid_joystick_device_open( int index, DIDEVICEINSTANCEW *filter, W
DWORD type;
GUID hid;
- TRACE( "index %d, product %s, instance %s\n", index, debugstr_guid( &filter->guidProduct ),
- debugstr_guid( &filter->guidInstance ) );
+ TRACE( "index %d, guid %s\n", index, debugstr_guid( guid ) );
HidD_GetHidGuid( &hid );
@@ -1601,10 +1599,10 @@ static HRESULT hid_joystick_device_open( int index, DIDEVICEINSTANCEW *filter, W
type != DEVPROP_TYPE_UINT32)
continue;
if (FAILED(hid_joystick_device_try_open( handle, detail->DevicePath, device, preparsed,
- attrs, caps, &instance, version )))
+ attrs, caps, instance, version )))
continue;
- if (device_instance_is_disabled( &instance, &override ))
+ if (device_instance_is_disabled( instance, &override ))
goto next;
if (override && SetupDiGetDeviceInstanceIdW( set, &devinfo, device_id, MAX_PATH, NULL ) &&
@@ -1621,13 +1619,13 @@ static HRESULT hid_joystick_device_open( int index, DIDEVICEINSTANCEW *filter, W
CloseHandle( *device );
HidD_FreePreparsedData( *preparsed );
if (FAILED(hid_joystick_device_try_open( handle, detail->DevicePath, device, preparsed,
- attrs, caps, &instance, version )))
+ attrs, caps, instance, version )))
continue;
}
/* enumerate device by GUID */
- if (index < 0 && IsEqualGUID( &filter->guidProduct, &instance.guidProduct )) break;
- if (index < 0 && IsEqualGUID( &filter->guidInstance, &instance.guidInstance )) break;
+ if (guid && (IsEqualGUID( guid, &instance->guidProduct ) || IsEqualGUID( guid, &instance->guidInstance )))
+ break;
/* enumerate all devices */
if (index >= 0 && !index--) break;
@@ -1644,7 +1642,6 @@ static HRESULT hid_joystick_device_open( int index, DIDEVICEINSTANCEW *filter, W
if (!*device || !*preparsed) return DIERR_DEVICENOTREG;
lstrcpynW( device_path, detail->DevicePath, MAX_PATH );
- *filter = instance;
return DI_OK;
}
@@ -1659,7 +1656,7 @@ HRESULT hid_joystick_enum_device( DWORD type, DWORD flags, DIDEVICEINSTANCEW *in
TRACE( "type %#lx, flags %#lx, instance %p, version %#lx, index %d\n", type, flags, instance, version, index );
- hr = hid_joystick_device_open( index, instance, device_path, &device, &preparsed,
+ hr = hid_joystick_device_open( index, NULL, instance, device_path, &device, &preparsed,
&attrs, &caps, version );
if (hr != DI_OK) return hr;
@@ -2008,12 +2005,6 @@ HRESULT hid_joystick_create_device( struct dinput *dinput, const GUID *guid, IDi
.dwHeaderSize = sizeof(filter),
.dwHow = DIPH_DEVICE,
};
- DIDEVICEINSTANCEW instance =
- {
- .dwSize = sizeof(instance),
- .guidProduct = *guid,
- .guidInstance = *guid
- };
DIPROPRANGE range =
{
.diph =
@@ -2043,35 +2034,21 @@ HRESULT hid_joystick_create_device( struct dinput *dinput, const GUID *guid, IDi
impl->base.read_event = CreateEventW( NULL, TRUE, FALSE, NULL );
impl->internal_ref = 1;
- instance.guidProduct.Data1 = dinput_pidvid_guid.Data1;
- instance.guidInstance.Data1 = hid_joystick_guid.Data1;
- if (IsEqualGUID( &dinput_pidvid_guid, &instance.guidProduct ))
- {
- instance.guidProduct = *guid;
- hr = hid_joystick_device_open( -1, &instance, impl->device_path, &impl->device, &impl->preparsed,
- &attrs, &impl->caps, dinput->dwVersion );
- }
- else if (IsEqualGUID( &hid_joystick_guid, &instance.guidInstance ))
- {
- instance.guidInstance = *guid;
- hr = hid_joystick_device_open( -1, &instance, impl->device_path, &impl->device, &impl->preparsed,
- &attrs, &impl->caps, dinput->dwVersion );
- }
- else if (!memcmp( &device_path_guid.Data4, instance.guidInstance.Data4, sizeof(device_path_guid.Data4) ))
+ if (!memcmp( device_path_guid.Data4, guid->Data4, sizeof(device_path_guid.Data4) ))
{
wcscpy( impl->device_path, *(const WCHAR **)guid );
hr = hid_joystick_device_try_open( 0, impl->device_path, &impl->device, &impl->preparsed, &attrs,
- &impl->caps, &instance, dinput->dwVersion );
+ &impl->caps, &impl->base.instance, dinput->dwVersion );
}
else
{
- hr = DIERR_DEVICENOTREG;
+ hr = hid_joystick_device_open( -1, guid, &impl->base.instance, impl->device_path, &impl->device,
+ &impl->preparsed, &attrs, &impl->caps, dinput->dwVersion );
}
if (hr != DI_OK) goto failed;
- impl->base.instance = instance;
- impl->base.caps.dwDevType = instance.dwDevType;
+ impl->base.caps.dwDevType = impl->base.instance.dwDevType;
impl->attrs = attrs;
list_init( &impl->effect_list );
--
2.35.1
More information about the wine-devel
mailing list