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 );