Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- dlls/dinput/device.c | 38 +++++++++++++++--------------------- dlls/dinput/device_private.h | 2 +- dlls/dinput/joystick_hid.c | 5 +++-- 3 files changed, 20 insertions(+), 25 deletions(-)
diff --git a/dlls/dinput/device.c b/dlls/dinput/device.c index d881669c06f..76214d73ece 100644 --- a/dlls/dinput/device.c +++ b/dlls/dinput/device.c @@ -244,7 +244,7 @@ LPDIOBJECTDATAFORMAT dataformat_to_odf_by_type(LPCDIDATAFORMAT df, int n, DWORD return NULL; }
-static BOOL match_device_object( DIDATAFORMAT *device_format, DIDATAFORMAT *user_format, +static BOOL match_device_object( const DIDATAFORMAT *device_format, DIDATAFORMAT *user_format, const DIDATAFORMAT *format, const DIOBJECTDATAFORMAT *match_obj, DWORD version ) { DWORD i, device_instance, instance = DIDFT_GETINSTANCE( match_obj->dwType ); @@ -276,11 +276,11 @@ static BOOL match_device_object( DIDATAFORMAT *device_format, DIDATAFORMAT *user
static HRESULT dinput_device_init_user_format( struct dinput_device *impl, const DIDATAFORMAT *format ) { - DIDATAFORMAT *user_format, *device_format = impl->device_format; + const DIDATAFORMAT *device_format = &impl->device_format; DIOBJECTDATAFORMAT *user_obj, *match_obj; + DIDATAFORMAT *user_format; DWORD i;
- if (!device_format) return DIERR_INVALIDPARAM; if (!(user_format = malloc( sizeof(DIDATAFORMAT) ))) return DIERR_OUTOFMEMORY; *user_format = *device_format; user_format->dwFlags = format->dwFlags; @@ -322,12 +322,12 @@ failed:
static int id_to_offset( struct dinput_device *impl, int id ) { - DIDATAFORMAT *device_format = impl->device_format, *user_format = impl->user_format; + DIDATAFORMAT *user_format = impl->user_format; DIOBJECTDATAFORMAT *user_obj;
if (!user_format) return -1;
- user_obj = user_format->rgodf + device_format->dwNumObjs; + user_obj = user_format->rgodf + impl->device_format.dwNumObjs; while (user_obj-- > user_format->rgodf) { if (!user_obj->dwType) continue; @@ -346,9 +346,9 @@ static DWORD semantic_to_obj_id( struct dinput_device *This, DWORD dwSemantic ) DWORD instance; int i;
- for (i = 0; i < This->device_format->dwNumObjs && !found; i++) + for (i = 0; i < This->device_format.dwNumObjs && !found; i++) { - LPDIOBJECTDATAFORMAT odf = dataformat_to_odf( This->device_format, i ); + LPDIOBJECTDATAFORMAT odf = dataformat_to_odf( &This->device_format, i );
if (byofs && value != odf->dwOfs) continue; if (!byofs && value != DIDFT_GETINSTANCE(odf->dwType)) continue; @@ -751,8 +751,7 @@ void dinput_device_destroy( IDirectInputDevice8W *iface ) free( This->data_queue );
/* Free data format */ - free( This->device_format->rgodf ); - free( This->device_format ); + free( This->device_format.rgodf ); dinput_device_release_user_format( This );
/* Free action mapping */ @@ -889,7 +888,8 @@ static HRESULT WINAPI dinput_device_EnumObjects( IDirectInputDevice8W *iface,
static HRESULT enum_object_filter_init( struct dinput_device *impl, DIPROPHEADER *filter ) { - DIDATAFORMAT *device_format = impl->device_format, *user_format = impl->user_format; + const DIDATAFORMAT *device_format = &impl->device_format; + DIDATAFORMAT *user_format = impl->user_format; DIOBJECTDATAFORMAT *device_obj, *user_obj;
if (filter->dwHow > DIPH_BYUSAGE) return DIERR_INVALIDPARAM; @@ -1535,8 +1535,9 @@ static HRESULT WINAPI dinput_device_GetObjectInfo( IDirectInputDevice8W *iface, static HRESULT WINAPI dinput_device_GetDeviceState( IDirectInputDevice8W *iface, DWORD size, void *data ) { struct dinput_device *impl = impl_from_IDirectInputDevice8W( iface ); - DIDATAFORMAT *device_format = impl->device_format, *user_format; + const DIDATAFORMAT *device_format = &impl->device_format; DIOBJECTDATAFORMAT *device_obj, *user_obj; + DIDATAFORMAT *user_format; BYTE *user_state = data; DIPROPHEADER filter = { @@ -1924,7 +1925,7 @@ static HRESULT WINAPI dinput_device_BuildActionMap( IDirectInputDevice8W *iface, break; default: devMask = DIGENRE_ANY; - df = impl->device_format; + df = &impl->device_format; break; }
@@ -2013,7 +2014,7 @@ static HRESULT WINAPI dinput_device_SetActionMap( IDirectInputDevice8W *iface, D df = &c_dfDIMouse2; break; default: - df = impl->device_format; + df = &impl->device_format; break; }
@@ -2158,14 +2159,8 @@ HRESULT dinput_device_alloc( SIZE_T size, const struct dinput_device_vtbl *vtbl, struct dinput *dinput, void **out ) { struct dinput_device *This; - DIDATAFORMAT *format;
if (!(This = calloc( 1, size ))) return DIERR_OUTOFMEMORY; - if (!(format = calloc( 1, sizeof(*format) ))) - { - free( This ); - return DIERR_OUTOFMEMORY; - }
This->IDirectInputDevice8A_iface.lpVtbl = &dinput_device_a_vtbl; This->IDirectInputDevice8W_iface.lpVtbl = &dinput_device_w_vtbl; @@ -2174,7 +2169,6 @@ HRESULT dinput_device_alloc( SIZE_T size, const struct dinput_device_vtbl *vtbl, This->instance.dwSize = sizeof(DIDEVICEINSTANCEW); This->caps.dwSize = sizeof(DIDEVCAPS); This->caps.dwFlags = DIDC_ATTACHED | DIDC_EMULATED; - This->device_format = format; This->device_gain = 10000; This->force_feedback_state = DIGFFS_STOPPED | DIGFFS_EMPTY; InitializeCriticalSection( &This->crit ); @@ -2204,7 +2198,7 @@ static const GUID *object_instance_guid( const DIDEVICEOBJECTINSTANCEW *instance static BOOL CALLBACK enum_objects_init( const DIDEVICEOBJECTINSTANCEW *instance, void *data ) { struct dinput_device *impl = impl_from_IDirectInputDevice8W( data ); - DIDATAFORMAT *format = impl->device_format; + DIDATAFORMAT *format = &impl->device_format; DIOBJECTDATAFORMAT *obj_format;
if (!format->rgodf) @@ -2240,7 +2234,7 @@ static BOOL CALLBACK enum_objects_init( const DIDEVICEOBJECTINSTANCEW *instance, HRESULT dinput_device_init( IDirectInputDevice8W *iface ) { struct dinput_device *impl = impl_from_IDirectInputDevice8W( iface ); - DIDATAFORMAT *format = impl->device_format; + DIDATAFORMAT *format = &impl->device_format; ULONG i, size;
IDirectInputDevice8_EnumObjects( iface, enum_objects_init, iface, DIDFT_ALL ); diff --git a/dlls/dinput/device_private.h b/dlls/dinput/device_private.h index 4e76d1ba738..2936e8ccb37 100644 --- a/dlls/dinput/device_private.h +++ b/dlls/dinput/device_private.h @@ -103,7 +103,7 @@ struct dinput_device BOOL overflow; /* return DI_BUFFEROVERFLOW in 'GetDeviceData' */ DWORD buffersize; /* size of the queue - set in 'SetProperty' */
- DIDATAFORMAT *device_format; + DIDATAFORMAT device_format; DIDATAFORMAT *user_format;
/* Action mapping */ diff --git a/dlls/dinput/joystick_hid.c b/dlls/dinput/joystick_hid.c index c97588d8a07..ef6cbfba65f 100644 --- a/dlls/dinput/joystick_hid.c +++ b/dlls/dinput/joystick_hid.c @@ -1224,7 +1224,7 @@ static HRESULT hid_joystick_read( IDirectInputDevice8W *iface ) }; struct hid_joystick *impl = impl_from_IDirectInputDevice8W( iface ); ULONG i, index, count, report_len = impl->caps.InputReportByteLength; - DIDATAFORMAT *format = impl->base.device_format; + const DIDATAFORMAT *format = &impl->base.device_format; char *report_buf = impl->input_report_buf; struct parse_device_state_params params; struct hid_joystick_effect *effect; @@ -2300,7 +2300,8 @@ static BOOL get_parameters_object_id( struct hid_joystick *impl, struct hid_valu static BOOL get_parameters_object_ofs( struct hid_joystick *impl, struct hid_value_caps *caps, DIDEVICEOBJECTINSTANCEW *instance, void *data ) { - DIDATAFORMAT *device_format = impl->base.device_format, *user_format = impl->base.user_format; + const DIDATAFORMAT *device_format = &impl->base.device_format; + DIDATAFORMAT *user_format = impl->base.user_format; DIOBJECTDATAFORMAT *device_obj, *user_obj;
if (!user_format) return DIENUM_CONTINUE;
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- dlls/dinput/dinput_main.c | 7 +++++++ dlls/dinput/joystick_hid.c | 2 -- dlls/dinput/keyboard.c | 6 ------ dlls/dinput/mouse.c | 6 ------ 4 files changed, 7 insertions(+), 14 deletions(-)
diff --git a/dlls/dinput/dinput_main.c b/dlls/dinput/dinput_main.c index 0cd5eb59588..41e143ad43c 100644 --- a/dlls/dinput/dinput_main.c +++ b/dlls/dinput/dinput_main.c @@ -545,6 +545,13 @@ static HRESULT WINAPI dinput7_CreateDeviceEx( IDirectInput7W *iface, const GUID else hr = hid_joystick_create_device( impl, guid, &device );
if (FAILED(hr)) return hr; + + if (FAILED(hr = dinput_device_init( device ))) + { + IDirectInputDevice8_Release( device ); + return hr; + } + hr = IDirectInputDevice8_QueryInterface( device, iid, out ); IDirectInputDevice8_Release( device ); return hr; diff --git a/dlls/dinput/joystick_hid.c b/dlls/dinput/joystick_hid.c index ef6cbfba65f..4e083871ba4 100644 --- a/dlls/dinput/joystick_hid.c +++ b/dlls/dinput/joystick_hid.c @@ -2138,8 +2138,6 @@ HRESULT hid_joystick_create_device( struct dinput *dinput, const GUID *guid, IDi impl->base.caps.dwFFDriverVersion = 1; }
- if (FAILED(hr = dinput_device_init( &impl->base.IDirectInputDevice8W_iface ))) goto failed; - *out = &impl->base.IDirectInputDevice8W_iface; return DI_OK;
diff --git a/dlls/dinput/keyboard.c b/dlls/dinput/keyboard.c index 1a1776ac408..f8f7a5a3195 100644 --- a/dlls/dinput/keyboard.c +++ b/dlls/dinput/keyboard.c @@ -183,12 +183,6 @@ HRESULT keyboard_create_device( struct dinput *dinput, const GUID *guid, IDirect impl->base.caps.dwFirmwareRevision = 100; impl->base.caps.dwHardwareRevision = 100;
- if (FAILED(hr = dinput_device_init( &impl->base.IDirectInputDevice8W_iface ))) - { - IDirectInputDevice_Release( &impl->base.IDirectInputDevice8W_iface ); - return hr; - } - *out = &impl->base.IDirectInputDevice8W_iface; return DI_OK; } diff --git a/dlls/dinput/mouse.c b/dlls/dinput/mouse.c index 46c065d78fa..fd1f9c03620 100644 --- a/dlls/dinput/mouse.c +++ b/dlls/dinput/mouse.c @@ -122,12 +122,6 @@ HRESULT mouse_create_device( struct dinput *dinput, const GUID *guid, IDirectInp if (appkey) RegCloseKey(appkey); if (hkey) RegCloseKey(hkey);
- if (FAILED(hr = dinput_device_init( &impl->base.IDirectInputDevice8W_iface ))) - { - IDirectInputDevice_Release( &impl->base.IDirectInputDevice8W_iface ); - return hr; - } - if (dinput->dwVersion >= 0x0800) { impl->base.use_raw_input = TRUE;
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- dlls/dinput/device.c | 2 +- dlls/dinput/device_private.h | 2 +- dlls/dinput/dinput_main.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/dlls/dinput/device.c b/dlls/dinput/device.c index 76214d73ece..ade728945c5 100644 --- a/dlls/dinput/device.c +++ b/dlls/dinput/device.c @@ -2231,7 +2231,7 @@ static BOOL CALLBACK enum_objects_init( const DIDEVICEOBJECTINSTANCEW *instance, return DIENUM_CONTINUE; }
-HRESULT dinput_device_init( IDirectInputDevice8W *iface ) +HRESULT dinput_device_init_device_format( IDirectInputDevice8W *iface ) { struct dinput_device *impl = impl_from_IDirectInputDevice8W( iface ); DIDATAFORMAT *format = &impl->device_format; diff --git a/dlls/dinput/device_private.h b/dlls/dinput/device_private.h index 2936e8ccb37..1d74e97e418 100644 --- a/dlls/dinput/device_private.h +++ b/dlls/dinput/device_private.h @@ -125,7 +125,7 @@ struct dinput_device
extern HRESULT dinput_device_alloc( SIZE_T size, const struct dinput_device_vtbl *vtbl, const GUID *guid, struct dinput *dinput, void **out ) DECLSPEC_HIDDEN; -extern HRESULT dinput_device_init( IDirectInputDevice8W *iface ); +extern HRESULT dinput_device_init_device_format( IDirectInputDevice8W *iface ); extern void dinput_device_destroy( IDirectInputDevice8W *iface );
extern BOOL get_app_key(HKEY*, HKEY*) DECLSPEC_HIDDEN; diff --git a/dlls/dinput/dinput_main.c b/dlls/dinput/dinput_main.c index 41e143ad43c..9738397ef5a 100644 --- a/dlls/dinput/dinput_main.c +++ b/dlls/dinput/dinput_main.c @@ -546,7 +546,7 @@ static HRESULT WINAPI dinput7_CreateDeviceEx( IDirectInput7W *iface, const GUID
if (FAILED(hr)) return hr;
- if (FAILED(hr = dinput_device_init( device ))) + if (FAILED(hr = dinput_device_init_device_format( device ))) { IDirectInputDevice8_Release( device ); return hr;
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- dlls/dinput/joystick_hid.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/dlls/dinput/joystick_hid.c b/dlls/dinput/joystick_hid.c index 4e083871ba4..bf7f090aca9 100644 --- a/dlls/dinput/joystick_hid.c +++ b/dlls/dinput/joystick_hid.c @@ -2066,7 +2066,11 @@ HRESULT hid_joystick_create_device( struct dinput *dinput, const GUID *guid, IDi &impl->caps, &instance, dinput->dwVersion )) hr = DIERR_DEVICENOTREG; } - if (hr != DI_OK) goto failed; + if (hr != DI_OK) + { + IDirectInputDevice_Release( &impl->base.IDirectInputDevice8W_iface ); + return hr; + }
impl->base.instance = instance; impl->base.caps.dwDevType = instance.dwDevType; @@ -2143,7 +2147,7 @@ HRESULT hid_joystick_create_device( struct dinput *dinput, const GUID *guid, IDi
failed: IDirectInputDevice_Release( &impl->base.IDirectInputDevice8W_iface ); - return hr; + return E_OUTOFMEMORY; }
static HRESULT WINAPI hid_joystick_effect_QueryInterface( IDirectInputEffect *iface, REFIID iid, void **out )
Rename it to dinput_device_init() accordingly.
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- dlls/dinput/device.c | 11 ++--------- dlls/dinput/device_private.h | 4 ++-- dlls/dinput/joystick_hid.c | 22 ++++++++++++++-------- dlls/dinput/keyboard.c | 6 +++--- dlls/dinput/mouse.c | 6 +++--- 5 files changed, 24 insertions(+), 25 deletions(-)
diff --git a/dlls/dinput/device.c b/dlls/dinput/device.c index ade728945c5..c1db844a65f 100644 --- a/dlls/dinput/device.c +++ b/dlls/dinput/device.c @@ -2155,13 +2155,9 @@ static const IDirectInputDevice8WVtbl dinput_device_w_vtbl = dinput_device_GetImageInfo, };
-HRESULT dinput_device_alloc( SIZE_T size, const struct dinput_device_vtbl *vtbl, const GUID *guid, - struct dinput *dinput, void **out ) +void dinput_device_init( struct dinput_device *This, const struct dinput_device_vtbl *vtbl, + const GUID *guid, struct dinput *dinput ) { - struct dinput_device *This; - - if (!(This = calloc( 1, size ))) return DIERR_OUTOFMEMORY; - This->IDirectInputDevice8A_iface.lpVtbl = &dinput_device_a_vtbl; This->IDirectInputDevice8W_iface.lpVtbl = &dinput_device_w_vtbl; This->ref = 1; @@ -2175,9 +2171,6 @@ HRESULT dinput_device_alloc( SIZE_T size, const struct dinput_device_vtbl *vtbl, This->dinput = dinput; IDirectInput_AddRef( &dinput->IDirectInput7A_iface ); This->vtbl = vtbl; - - *out = This; - return DI_OK; }
static const GUID *object_instance_guid( const DIDEVICEOBJECTINSTANCEW *instance ) diff --git a/dlls/dinput/device_private.h b/dlls/dinput/device_private.h index 1d74e97e418..da45c52d178 100644 --- a/dlls/dinput/device_private.h +++ b/dlls/dinput/device_private.h @@ -123,8 +123,8 @@ struct dinput_device struct object_properties *object_properties; };
-extern HRESULT dinput_device_alloc( SIZE_T size, const struct dinput_device_vtbl *vtbl, const GUID *guid, - struct dinput *dinput, void **out ) DECLSPEC_HIDDEN; +extern void dinput_device_init( struct dinput_device *This, const struct dinput_device_vtbl *vtbl, + const GUID *guid, struct dinput *dinput ); extern HRESULT dinput_device_init_device_format( IDirectInputDevice8W *iface ); extern void dinput_device_destroy( IDirectInputDevice8W *iface );
diff --git a/dlls/dinput/joystick_hid.c b/dlls/dinput/joystick_hid.c index bf7f090aca9..a77e161b477 100644 --- a/dlls/dinput/joystick_hid.c +++ b/dlls/dinput/joystick_hid.c @@ -2049,27 +2049,33 @@ HRESULT hid_joystick_create_device( struct dinput *dinput, const GUID *guid, IDi if (!IsEqualGUID( &device_path_guid, &instance.guidInstance )) return DIERR_DEVICENOTREG; }
- hr = dinput_device_alloc( sizeof(struct hid_joystick), &hid_joystick_vtbl, guid, dinput, (void **)&impl ); - if (FAILED(hr)) return hr; + if (!(impl = calloc( 1, sizeof(*impl) ))) + return E_OUTOFMEMORY; + dinput_device_init( &impl->base, &hid_joystick_vtbl, guid, dinput ); impl->base.crit.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": hid_joystick.base.crit"); impl->base.dwCoopLevel = DISCL_NONEXCLUSIVE | DISCL_BACKGROUND; impl->base.read_event = CreateEventW( NULL, TRUE, FALSE, NULL ); impl->internal_ref = 1;
if (!IsEqualGUID( &device_path_guid, &instance.guidInstance )) + { hr = hid_joystick_device_open( -1, &instance, impl->device_path, &impl->device, &impl->preparsed, &attrs, &impl->caps, dinput->dwVersion ); + if (hr != DI_OK) + { + IDirectInputDevice_Release( &impl->base.IDirectInputDevice8W_iface ); + return hr; + } + } else { wcscpy( impl->device_path, *(const WCHAR **)guid ); if (!hid_joystick_device_try_open( 0, impl->device_path, &impl->device, &impl->preparsed, &attrs, &impl->caps, &instance, dinput->dwVersion )) - hr = DIERR_DEVICENOTREG; - } - if (hr != DI_OK) - { - IDirectInputDevice_Release( &impl->base.IDirectInputDevice8W_iface ); - return hr; + { + IDirectInputDevice_Release( &impl->base.IDirectInputDevice8W_iface ); + return DIERR_DEVICENOTREG; + } }
impl->base.instance = instance; diff --git a/dlls/dinput/keyboard.c b/dlls/dinput/keyboard.c index f8f7a5a3195..04deabd2df3 100644 --- a/dlls/dinput/keyboard.c +++ b/dlls/dinput/keyboard.c @@ -167,15 +167,15 @@ HRESULT keyboard_enum_device( DWORD type, DWORD flags, DIDEVICEINSTANCEW *instan HRESULT keyboard_create_device( struct dinput *dinput, const GUID *guid, IDirectInputDevice8W **out ) { struct keyboard *impl; - HRESULT hr;
TRACE( "dinput %p, guid %s, out %p.\n", dinput, debugstr_guid( guid ), out );
*out = NULL; if (!IsEqualGUID( &GUID_SysKeyboard, guid )) return DIERR_DEVICENOTREG;
- if (FAILED(hr = dinput_device_alloc( sizeof(struct keyboard), &keyboard_vtbl, guid, dinput, (void **)&impl ))) - return hr; + if (!(impl = calloc( 1, sizeof(*impl) ))) + return E_OUTOFMEMORY; + dinput_device_init( &impl->base, &keyboard_vtbl, guid, dinput ); impl->base.crit.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": struct keyboard*->base.crit");
keyboard_enum_device( 0, 0, &impl->base.instance, dinput->dwVersion ); diff --git a/dlls/dinput/mouse.c b/dlls/dinput/mouse.c index fd1f9c03620..8730e41636f 100644 --- a/dlls/dinput/mouse.c +++ b/dlls/dinput/mouse.c @@ -96,15 +96,15 @@ HRESULT mouse_create_device( struct dinput *dinput, const GUID *guid, IDirectInp struct mouse *impl; HKEY hkey, appkey; WCHAR buffer[20]; - HRESULT hr;
TRACE( "dinput %p, guid %s, out %p\n", dinput, debugstr_guid( guid ), out );
*out = NULL; if (!IsEqualGUID( &GUID_SysMouse, guid )) return DIERR_DEVICENOTREG;
- if (FAILED(hr = dinput_device_alloc( sizeof(struct mouse), &mouse_vtbl, guid, dinput, (void **)&impl ))) - return hr; + if (!(impl = calloc( 1, sizeof(*impl) ))) + return E_OUTOFMEMORY; + dinput_device_init( &impl->base, &mouse_vtbl, guid, dinput ); impl->base.crit.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": struct mouse*->base.crit");
mouse_enum_device( 0, 0, &impl->base.instance, dinput->dwVersion );