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;