From: Zebediah Figura zfigura@codeweavers.com
Signed-off-by: Zebediah Figura zfigura@codeweavers.com Signed-off-by: Rémi Bernon rbernon@codeweavers.com ---
Supersedes: 235664-235668
dlls/dinput/device.c | 35 +++++++++++++---------------------- dlls/dinput/device_private.h | 2 +- dlls/dinput/joystick_hid.c | 4 ++-- 3 files changed, 16 insertions(+), 25 deletions(-)
diff --git a/dlls/dinput/device.c b/dlls/dinput/device.c index d881669c06f..a23398ac794 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,10 @@ 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; + DIDATAFORMAT *user_format, *device_format = &impl->device_format; DIOBJECTDATAFORMAT *user_obj, *match_obj; 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 +321,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 +345,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 +750,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 +887,7 @@ 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; + DIDATAFORMAT *device_format = &impl->device_format, *user_format = impl->user_format; DIOBJECTDATAFORMAT *device_obj, *user_obj;
if (filter->dwHow > DIPH_BYUSAGE) return DIERR_INVALIDPARAM; @@ -1535,7 +1533,7 @@ 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; + DIDATAFORMAT *device_format = &impl->device_format, *user_format; DIOBJECTDATAFORMAT *device_obj, *user_obj; BYTE *user_state = data; DIPROPHEADER filter = @@ -1924,7 +1922,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 +2011,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 +2156,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 +2166,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 +2195,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 +2231,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..f0b243091b9 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; + 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,7 @@ 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; + DIDATAFORMAT *device_format = &impl->base.device_format, *user_format = impl->base.user_format; DIOBJECTDATAFORMAT *device_obj, *user_obj;
if (!user_format) return DIENUM_CONTINUE;
Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/dinput/device.c | 40 +++++++++++++++--------------------- dlls/dinput/device_private.h | 2 +- dlls/dinput/joystick_hid.c | 4 ++-- dlls/dinput/mouse.c | 6 +++--- 4 files changed, 22 insertions(+), 30 deletions(-)
diff --git a/dlls/dinput/device.c b/dlls/dinput/device.c index a23398ac794..bd2064b1484 100644 --- a/dlls/dinput/device.c +++ b/dlls/dinput/device.c @@ -210,9 +210,8 @@ BOOL device_instance_is_disabled( DIDEVICEINSTANCEW *instance, BOOL *override )
static void dinput_device_release_user_format( struct dinput_device *impl ) { - if (impl->user_format) free( impl->user_format->rgodf ); - free( impl->user_format ); - impl->user_format = NULL; + free( impl->user_format.rgodf ); + impl->user_format.rgodf = NULL; }
static inline LPDIOBJECTDATAFORMAT dataformat_to_odf(LPCDIDATAFORMAT df, int idx) @@ -276,20 +275,15 @@ static BOOL match_device_object( const DIDATAFORMAT *device_format, DIDATAFORMAT
static HRESULT dinput_device_init_user_format( struct dinput_device *impl, const DIDATAFORMAT *format ) { - DIDATAFORMAT *user_format, *device_format = &impl->device_format; + DIDATAFORMAT *user_format = &impl->user_format, *device_format = &impl->device_format; DIOBJECTDATAFORMAT *user_obj, *match_obj; DWORD i;
- if (!(user_format = malloc( sizeof(DIDATAFORMAT) ))) return DIERR_OUTOFMEMORY; *user_format = *device_format; user_format->dwFlags = format->dwFlags; user_format->dwDataSize = format->dwDataSize; user_format->dwNumObjs += format->dwNumObjs; - if (!(user_format->rgodf = calloc( user_format->dwNumObjs, sizeof(DIOBJECTDATAFORMAT) ))) - { - free( user_format ); - return DIERR_OUTOFMEMORY; - } + if (!(user_format->rgodf = calloc( user_format->dwNumObjs, sizeof(DIOBJECTDATAFORMAT) ))) return DIERR_OUTOFMEMORY;
user_obj = user_format->rgodf + user_format->dwNumObjs; while (user_obj-- > user_format->rgodf) user_obj->dwType |= DIDFT_OPTIONAL; @@ -310,21 +304,20 @@ static HRESULT dinput_device_init_user_format( struct dinput_device *impl, const user_obj = user_format->rgodf + user_format->dwNumObjs; while (user_obj-- > user_format->rgodf) user_obj->dwType &= ~DIDFT_OPTIONAL;
- impl->user_format = user_format; return DI_OK;
failed: free( user_format->rgodf ); - free( user_format ); + user_format->rgodf = NULL; return DIERR_INVALIDPARAM; }
static int id_to_offset( struct dinput_device *impl, int id ) { - DIDATAFORMAT *user_format = impl->user_format; + DIDATAFORMAT *user_format = &impl->user_format; DIOBJECTDATAFORMAT *user_obj;
- if (!user_format) return -1; + if (!user_format->rgodf) return -1;
user_obj = user_format->rgodf + impl->device_format.dwNumObjs; while (user_obj-- > user_format->rgodf) @@ -582,7 +575,7 @@ static HRESULT WINAPI dinput_device_Acquire( IDirectInputDevice8W *iface ) EnterCriticalSection( &impl->crit ); if (impl->status == STATUS_ACQUIRED) hr = DI_NOEFFECT; - else if (!impl->user_format) + else if (!impl->user_format.rgodf) hr = DIERR_INVALIDPARAM; else if ((impl->dwCoopLevel & DISCL_FOREGROUND) && impl->win != GetForegroundWindow()) hr = DIERR_OTHERAPPHASPRIO; @@ -887,14 +880,14 @@ 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; + DIDATAFORMAT *device_format = &impl->device_format, *user_format = &impl->user_format; DIOBJECTDATAFORMAT *device_obj, *user_obj;
if (filter->dwHow > DIPH_BYUSAGE) return DIERR_INVALIDPARAM; if (filter->dwHow == DIPH_BYUSAGE && !(impl->instance.dwDevType & DIDEVTYPE_HID)) return DIERR_UNSUPPORTED; if (filter->dwHow != DIPH_BYOFFSET) return DI_OK;
- if (!impl->user_format) return DIERR_NOTFOUND; + if (!user_format->rgodf) return DIERR_NOTFOUND;
user_obj = user_format->rgodf + device_format->dwNumObjs; device_obj = device_format->rgodf + device_format->dwNumObjs; @@ -1411,11 +1404,10 @@ static HRESULT WINAPI dinput_device_set_property( IDirectInputDevice8W *iface, c const DIPROPDWORD *value = (const DIPROPDWORD *)header;
TRACE( "Axis mode: %s\n", value->dwData == DIPROPAXISMODE_ABS ? "absolute" : "relative" ); - if (impl->user_format) - { - impl->user_format->dwFlags &= ~DIDFT_AXIS; - impl->user_format->dwFlags |= value->dwData == DIPROPAXISMODE_ABS ? DIDF_ABSAXIS : DIDF_RELAXIS; - } + + impl->user_format.dwFlags &= ~DIDFT_AXIS; + impl->user_format.dwFlags |= value->dwData == DIPROPAXISMODE_ABS ? DIDF_ABSAXIS : DIDF_RELAXIS; + return DI_OK; } case (DWORD_PTR)DIPROP_BUFFERSIZE: @@ -1533,7 +1525,7 @@ 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; + DIDATAFORMAT *device_format = &impl->device_format, *user_format = &impl->user_format; DIOBJECTDATAFORMAT *device_obj, *user_obj; BYTE *user_state = data; DIPROPHEADER filter = @@ -1556,7 +1548,7 @@ static HRESULT WINAPI dinput_device_GetDeviceState( IDirectInputDevice8W *iface, hr = DIERR_INPUTLOST; else if (impl->status != STATUS_ACQUIRED) hr = DIERR_NOTACQUIRED; - else if (!(user_format = impl->user_format)) + else if (!user_format->rgodf) hr = DIERR_INVALIDPARAM; else if (size != user_format->dwDataSize) hr = DIERR_INVALIDPARAM; diff --git a/dlls/dinput/device_private.h b/dlls/dinput/device_private.h index 2936e8ccb37..f23542a660c 100644 --- a/dlls/dinput/device_private.h +++ b/dlls/dinput/device_private.h @@ -104,7 +104,7 @@ struct dinput_device DWORD buffersize; /* size of the queue - set in 'SetProperty' */
DIDATAFORMAT device_format; - DIDATAFORMAT *user_format; + DIDATAFORMAT user_format;
/* Action mapping */ int num_actions; /* number of actions mapped */ diff --git a/dlls/dinput/joystick_hid.c b/dlls/dinput/joystick_hid.c index f0b243091b9..3aa6d6b5ad3 100644 --- a/dlls/dinput/joystick_hid.c +++ b/dlls/dinput/joystick_hid.c @@ -2300,10 +2300,10 @@ 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; + DIDATAFORMAT *device_format = &impl->base.device_format, *user_format = &impl->base.user_format; DIOBJECTDATAFORMAT *device_obj, *user_obj;
- if (!user_format) return DIENUM_CONTINUE; + if (!user_format->rgodf) return DIENUM_CONTINUE;
user_obj = user_format->rgodf + device_format->dwNumObjs; device_obj = device_format->rgodf + device_format->dwNumObjs; diff --git a/dlls/dinput/mouse.c b/dlls/dinput/mouse.c index 46c065d78fa..2a004d80143 100644 --- a/dlls/dinput/mouse.c +++ b/dlls/dinput/mouse.c @@ -179,7 +179,7 @@ void dinput_mouse_rawinput_hook( IDirectInputDevice8W *iface, WPARAM wparam, LPA state->lX += rel.x; state->lY += rel.y;
- if (impl->base.user_format->dwFlags & DIDF_ABSAXIS) + if (impl->base.user_format.dwFlags & DIDF_ABSAXIS) { pt.x = state->lX; pt.y = state->lY; @@ -259,7 +259,7 @@ int dinput_mouse_hook( IDirectInputDevice8W *iface, WPARAM wparam, LPARAM lparam state->lX += pt.x = hook->pt.x - pt.x; state->lY += pt.y = hook->pt.y - pt.y;
- if (impl->base.user_format->dwFlags & DIDF_ABSAXIS) + if (impl->base.user_format.dwFlags & DIDF_ABSAXIS) { pt1.x = state->lX; pt1.y = state->lY; @@ -399,7 +399,7 @@ static HRESULT mouse_acquire( IDirectInputDevice8W *iface )
/* Init the mouse state */ GetCursorPos( &point ); - if (impl->base.user_format->dwFlags & DIDF_ABSAXIS) + if (impl->base.user_format.dwFlags & DIDF_ABSAXIS) { state->lX = point.x; state->lY = point.y;
From: Zebediah Figura zfigura@codeweavers.com
Signed-off-by: Zebediah Figura zfigura@codeweavers.com Signed-off-by: Rémi Bernon rbernon@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 3aa6d6b5ad3..ddd67be4fd0 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 2a004d80143..622dc1994d1 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;
From: Zebediah Figura zfigura@codeweavers.com
Signed-off-by: Zebediah Figura zfigura@codeweavers.com Signed-off-by: Rémi Bernon rbernon@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 bd2064b1484..6636eae0e42 100644 --- a/dlls/dinput/device.c +++ b/dlls/dinput/device.c @@ -2220,7 +2220,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 f23542a660c..772c5d35786 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;
From: Zebediah Figura zfigura@codeweavers.com
Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/dinput/joystick_hid.c | 1 + 1 file changed, 1 insertion(+)
diff --git a/dlls/dinput/joystick_hid.c b/dlls/dinput/joystick_hid.c index ddd67be4fd0..171ef4e2640 100644 --- a/dlls/dinput/joystick_hid.c +++ b/dlls/dinput/joystick_hid.c @@ -2073,6 +2073,7 @@ HRESULT hid_joystick_create_device( struct dinput *dinput, const GUID *guid, IDi impl->attrs = attrs; list_init( &impl->effect_list );
+ hr = E_OUTOFMEMORY; preparsed = (struct hid_preparsed_data *)impl->preparsed; size = preparsed->input_caps_count * sizeof(struct object_properties); if (!(object_properties = calloc( 1, size ))) goto failed;
Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/dinput/joystick_hid.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-)
diff --git a/dlls/dinput/joystick_hid.c b/dlls/dinput/joystick_hid.c index 171ef4e2640..017755f3feb 100644 --- a/dlls/dinput/joystick_hid.c +++ b/dlls/dinput/joystick_hid.c @@ -1413,9 +1413,9 @@ static DWORD device_type_for_version( DWORD type, DWORD version ) } }
-static BOOL hid_joystick_device_try_open( UINT32 handle, const WCHAR *path, HANDLE *device, - PHIDP_PREPARSED_DATA *preparsed, HIDD_ATTRIBUTES *attrs, - HIDP_CAPS *caps, DIDEVICEINSTANCEW *instance, DWORD version ) +static HRESULT hid_joystick_device_try_open( UINT32 handle, const WCHAR *path, HANDLE *device, + PHIDP_PREPARSED_DATA *preparsed, HIDD_ATTRIBUTES *attrs, + HIDP_CAPS *caps, DIDEVICEINSTANCEW *instance, DWORD version ) { BOOL has_accelerator, has_brake, has_clutch, has_z, has_pov; PHIDP_PREPARSED_DATA preparsed_data = NULL; @@ -1430,7 +1430,7 @@ static BOOL hid_joystick_device_try_open( UINT32 handle, const WCHAR *path, HAND
device_file = CreateFileW( path, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED | FILE_FLAG_NO_BUFFERING, 0 ); - if (device_file == INVALID_HANDLE_VALUE) return FALSE; + if (device_file == INVALID_HANDLE_VALUE) return DIERR_DEVICENOTREG;
if (!HidD_GetPreparsedData( device_file, &preparsed_data )) goto failed; if (!HidD_GetAttributes( device_file, attrs )) goto failed; @@ -1556,12 +1556,12 @@ static BOOL hid_joystick_device_try_open( UINT32 handle, const WCHAR *path, HAND
*device = device_file; *preparsed = preparsed_data; - return TRUE; + return DI_OK;
failed: CloseHandle( device_file ); HidD_FreePreparsedData( preparsed_data ); - return FALSE; + return DIERR_DEVICENOTREG; }
static HRESULT hid_joystick_device_open( int index, DIDEVICEINSTANCEW *filter, WCHAR *device_path, @@ -1600,8 +1600,8 @@ static HRESULT hid_joystick_device_open( int index, DIDEVICEINSTANCEW *filter, W (BYTE *)&handle, sizeof(handle), NULL, 0 ) || type != DEVPROP_TYPE_UINT32) continue; - if (!hid_joystick_device_try_open( handle, detail->DevicePath, device, preparsed, - attrs, caps, &instance, version )) + if (FAILED(hid_joystick_device_try_open( handle, detail->DevicePath, device, preparsed, + attrs, caps, &instance, version ))) continue;
if (device_instance_is_disabled( &instance, &override )) @@ -1620,8 +1620,8 @@ static HRESULT hid_joystick_device_open( int index, DIDEVICEINSTANCEW *filter, W
CloseHandle( *device ); HidD_FreePreparsedData( *preparsed ); - if (!hid_joystick_device_try_open( handle, detail->DevicePath, device, preparsed, - attrs, caps, &instance, version )) + if (FAILED(hid_joystick_device_try_open( handle, detail->DevicePath, device, preparsed, + attrs, caps, &instance, version ))) continue; }
@@ -2062,9 +2062,8 @@ HRESULT hid_joystick_create_device( struct dinput *dinput, const GUID *guid, IDi 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; + hr = hid_joystick_device_try_open( 0, impl->device_path, &impl->device, &impl->preparsed, &attrs, + &impl->caps, &instance, dinput->dwVersion ); } if (hr != DI_OK) goto failed;
Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/dinput/device.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-)
diff --git a/dlls/dinput/device.c b/dlls/dinput/device.c index 6636eae0e42..6af1500ab64 100644 --- a/dlls/dinput/device.c +++ b/dlls/dinput/device.c @@ -2147,25 +2147,25 @@ static const IDirectInputDevice8WVtbl dinput_device_w_vtbl = HRESULT dinput_device_alloc( SIZE_T size, const struct dinput_device_vtbl *vtbl, const GUID *guid, struct dinput *dinput, void **out ) { - struct dinput_device *This; + struct dinput_device *device;
- if (!(This = calloc( 1, size ))) return DIERR_OUTOFMEMORY; + if (!(device = 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; - This->guid = *guid; - This->instance.dwSize = sizeof(DIDEVICEINSTANCEW); - This->caps.dwSize = sizeof(DIDEVCAPS); - This->caps.dwFlags = DIDC_ATTACHED | DIDC_EMULATED; - This->device_gain = 10000; - This->force_feedback_state = DIGFFS_STOPPED | DIGFFS_EMPTY; - InitializeCriticalSection( &This->crit ); - This->dinput = dinput; + device->IDirectInputDevice8A_iface.lpVtbl = &dinput_device_a_vtbl; + device->IDirectInputDevice8W_iface.lpVtbl = &dinput_device_w_vtbl; + device->ref = 1; + device->guid = *guid; + device->instance.dwSize = sizeof(DIDEVICEINSTANCEW); + device->caps.dwSize = sizeof(DIDEVCAPS); + device->caps.dwFlags = DIDC_ATTACHED | DIDC_EMULATED; + device->device_gain = 10000; + device->force_feedback_state = DIGFFS_STOPPED | DIGFFS_EMPTY; + InitializeCriticalSection( &device->crit ); + device->dinput = dinput; IDirectInput_AddRef( &dinput->IDirectInput7A_iface ); - This->vtbl = vtbl; + device->vtbl = vtbl;
- *out = This; + *out = device; return DI_OK; }
From: Zebediah Figura zfigura@codeweavers.com
Rename it to dinput_device_init() accordingly.
Signed-off-by: Zebediah Figura zfigura@codeweavers.com Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/dinput/device.c | 11 ++--------- dlls/dinput/device_private.h | 4 ++-- dlls/dinput/joystick_hid.c | 4 ++-- dlls/dinput/keyboard.c | 5 ++--- dlls/dinput/mouse.c | 5 ++--- 5 files changed, 10 insertions(+), 19 deletions(-)
diff --git a/dlls/dinput/device.c b/dlls/dinput/device.c index 6af1500ab64..9e7cb20453c 100644 --- a/dlls/dinput/device.c +++ b/dlls/dinput/device.c @@ -2144,13 +2144,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 *device, const struct dinput_device_vtbl *vtbl, + const GUID *guid, struct dinput *dinput ) { - struct dinput_device *device; - - if (!(device = calloc( 1, size ))) return DIERR_OUTOFMEMORY; - device->IDirectInputDevice8A_iface.lpVtbl = &dinput_device_a_vtbl; device->IDirectInputDevice8W_iface.lpVtbl = &dinput_device_w_vtbl; device->ref = 1; @@ -2164,9 +2160,6 @@ HRESULT dinput_device_alloc( SIZE_T size, const struct dinput_device_vtbl *vtbl, device->dinput = dinput; IDirectInput_AddRef( &dinput->IDirectInput7A_iface ); device->vtbl = vtbl; - - *out = device; - 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 772c5d35786..31696f00536 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 *device, 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 017755f3feb..5fdc563054b 100644 --- a/dlls/dinput/joystick_hid.c +++ b/dlls/dinput/joystick_hid.c @@ -2049,8 +2049,8 @@ 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 ); diff --git a/dlls/dinput/keyboard.c b/dlls/dinput/keyboard.c index f8f7a5a3195..873a2d98434 100644 --- a/dlls/dinput/keyboard.c +++ b/dlls/dinput/keyboard.c @@ -167,15 +167,14 @@ 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 622dc1994d1..1572e73bac2 100644 --- a/dlls/dinput/mouse.c +++ b/dlls/dinput/mouse.c @@ -96,15 +96,14 @@ 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 );