dinput: Make device creation error handling consistent.

Signed-off-by: Rémi Bernon <rbernon@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Rémi Bernon 2021-05-28 11:41:26 +02:00 committed by Alexandre Julliard
parent e79fa1866c
commit ad8e3727c1
5 changed files with 40 additions and 48 deletions

View file

@ -451,8 +451,7 @@ static HRESULT joydev_enum_deviceW(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINS
return S_FALSE;
}
static HRESULT alloc_device(REFGUID rguid, IDirectInputImpl *dinput,
JoystickImpl **pdev, unsigned short index)
static HRESULT alloc_device( REFGUID rguid, IDirectInputImpl *dinput, JoystickImpl **out, unsigned short index )
{
DWORD i;
JoystickImpl* newDevice;
@ -461,14 +460,10 @@ static HRESULT alloc_device(REFGUID rguid, IDirectInputImpl *dinput,
int idx = 0;
DIDEVICEINSTANCEW ddi;
TRACE("%s %p %p %hu\n", debugstr_guid(rguid), dinput, pdev, index);
TRACE( "%s %p %p %hu\n", debugstr_guid( rguid ), dinput, out, index );
newDevice = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(JoystickImpl));
if (newDevice == 0) {
WARN("out of memory\n");
*pdev = 0;
return DIERR_OUTOFMEMORY;
}
if (!newDevice) return DIERR_OUTOFMEMORY;
newDevice->joydev = &joystick_devices[index];
newDevice->joyfd = -1;
@ -564,8 +559,7 @@ static HRESULT alloc_device(REFGUID rguid, IDirectInputImpl *dinput,
_dump_DIDEVCAPS(&newDevice->generic.devcaps);
}
*pdev = newDevice;
*out = newDevice;
return DI_OK;
FAILED:
@ -576,8 +570,6 @@ FAILED1:
release_DataFormat(&newDevice->generic.base.data_format);
HeapFree(GetProcessHeap(),0,newDevice->generic.axis_map);
HeapFree(GetProcessHeap(),0,newDevice);
*pdev = 0;
return hr;
}
@ -641,8 +633,9 @@ static HRESULT joydev_create_device(IDirectInputImpl *dinput, REFGUID rguid, REF
return DIERR_NOINTERFACE;
}
hr = alloc_device(rguid, dinput, &This, index);
if (!This) return hr;
if (FAILED(hr = alloc_device( rguid, dinput, &This, index ))) return hr;
TRACE( "Created a Joystick device (%p)\n", This );
if (unicode)
*pdev = &This->generic.base.IDirectInputDevice8W_iface;

View file

@ -444,7 +444,7 @@ static HRESULT joydev_enum_deviceW(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINS
return S_FALSE;
}
static JoystickImpl *alloc_device(REFGUID rguid, IDirectInputImpl *dinput, unsigned short index)
static HRESULT alloc_device( REFGUID rguid, IDirectInputImpl *dinput, JoystickImpl **out, unsigned short index )
{
JoystickImpl* newDevice;
LPDIDATAFORMAT df = NULL;
@ -453,7 +453,7 @@ static JoystickImpl *alloc_device(REFGUID rguid, IDirectInputImpl *dinput, unsig
DIDEVICEINSTANCEW ddi;
newDevice = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(JoystickImpl));
if (!newDevice) return NULL;
if (!newDevice) return DIERR_OUTOFMEMORY;
newDevice->generic.base.IDirectInputDevice8A_iface.lpVtbl = &JoystickAvt;
newDevice->generic.base.IDirectInputDevice8W_iface.lpVtbl = &JoystickWvt;
@ -584,14 +584,15 @@ static JoystickImpl *alloc_device(REFGUID rguid, IDirectInputImpl *dinput, unsig
IDirectInput_AddRef(&newDevice->generic.base.dinput->IDirectInput7A_iface);
return newDevice;
*out = newDevice;
return DI_OK;
failed:
if (df) HeapFree(GetProcessHeap(), 0, df->rgodf);
HeapFree(GetProcessHeap(), 0, df);
HeapFree(GetProcessHeap(), 0, newDevice->generic.axis_map);
HeapFree(GetProcessHeap(), 0, newDevice);
return NULL;
return DIERR_OUTOFMEMORY;
}
/******************************************************************************
@ -630,6 +631,7 @@ static HRESULT joydev_create_device(IDirectInputImpl *dinput, REFGUID rguid, REF
have_joydevs && index < have_joydevs)
{
JoystickImpl *This;
HRESULT hr;
if (riid == NULL)
;/* nothing */
@ -653,10 +655,9 @@ static HRESULT joydev_create_device(IDirectInputImpl *dinput, REFGUID rguid, REF
return DIERR_NOINTERFACE;
}
This = alloc_device(rguid, dinput, index);
TRACE("Created a Joystick device (%p)\n", This);
if (FAILED(hr = alloc_device( rguid, dinput, &This, index ))) return hr;
if (!This) return DIERR_OUTOFMEMORY;
TRACE( "Created a Joystick device (%p)\n", This );
if (unicode)
*pdev = &This->generic.base.IDirectInputDevice8W_iface;

View file

@ -1105,8 +1105,7 @@ static BOOL osx_axis_has_ff(FFCAPABILITIES *ffcaps, UInt8 axis)
return FALSE;
}
static HRESULT alloc_device(REFGUID rguid, IDirectInputImpl *dinput,
JoystickImpl **pdev, unsigned short index)
static HRESULT alloc_device( REFGUID rguid, IDirectInputImpl *dinput, JoystickImpl **out, unsigned short index )
{
DWORD i;
IOHIDDeviceRef device;
@ -1119,14 +1118,10 @@ static HRESULT alloc_device(REFGUID rguid, IDirectInputImpl *dinput,
int slider_count = 0;
FFCAPABILITIES ffcaps;
TRACE("%s %p %p %hu\n", debugstr_guid(rguid), dinput, pdev, index);
TRACE( "%s %p %p %hu\n", debugstr_guid( rguid ), dinput, out, index );
newDevice = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(JoystickImpl));
if (newDevice == 0) {
WARN("out of memory\n");
*pdev = 0;
return DIERR_OUTOFMEMORY;
}
if (!newDevice) return DIERR_OUTOFMEMORY;
newDevice->id = index;
@ -1287,8 +1282,7 @@ static HRESULT alloc_device(REFGUID rguid, IDirectInputImpl *dinput,
_dump_DIDEVCAPS(&newDevice->generic.devcaps);
}
*pdev = newDevice;
*out = newDevice;
return DI_OK;
FAILED:
@ -1300,8 +1294,6 @@ FAILED:
release_DataFormat(&newDevice->generic.base.data_format);
HeapFree(GetProcessHeap(),0,newDevice->generic.name);
HeapFree(GetProcessHeap(),0,newDevice);
*pdev = 0;
return hr;
}
@ -1380,8 +1372,9 @@ static HRESULT joydev_create_device(IDirectInputImpl *dinput, REFGUID rguid, REF
return DIERR_NOINTERFACE;
}
hr = alloc_device(rguid, dinput, &This, index);
if (!This) return hr;
if (FAILED(hr = alloc_device( rguid, dinput, &This, index ))) return hr;
TRACE( "Created a Joystick device (%p)\n", This );
if (unicode)
*pdev = &This->generic.base.IDirectInputDevice8W_iface;

View file

@ -240,13 +240,15 @@ static HRESULT keyboarddev_enum_deviceW(DWORD dwDevType, DWORD dwFlags, LPDIDEVI
return S_FALSE;
}
static SysKeyboardImpl *alloc_device(REFGUID rguid, IDirectInputImpl *dinput)
static HRESULT alloc_device( REFGUID rguid, IDirectInputImpl *dinput, SysKeyboardImpl **out )
{
SysKeyboardImpl* newDevice;
LPDIDATAFORMAT df = NULL;
int i, idx = 0;
newDevice = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(SysKeyboardImpl));
if (!newDevice) return DIERR_OUTOFMEMORY;
newDevice->base.IDirectInputDevice8A_iface.lpVtbl = &SysKeyboardAvt;
newDevice->base.IDirectInputDevice8W_iface.lpVtbl = &SysKeyboardWvt;
newDevice->base.ref = 1;
@ -278,13 +280,14 @@ static SysKeyboardImpl *alloc_device(REFGUID rguid, IDirectInputImpl *dinput)
newDevice->base.data_format.wine_df = df;
IDirectInput_AddRef(&newDevice->base.dinput->IDirectInput7A_iface);
return newDevice;
*out = newDevice;
return DI_OK;
failed:
if (df) HeapFree(GetProcessHeap(), 0, df->rgodf);
HeapFree(GetProcessHeap(), 0, df);
HeapFree(GetProcessHeap(), 0, newDevice);
return NULL;
return DIERR_OUTOFMEMORY;
}
@ -296,6 +299,7 @@ static HRESULT keyboarddev_create_device(IDirectInputImpl *dinput, REFGUID rguid
if (IsEqualGUID(&GUID_SysKeyboard, rguid)) /* Wine Keyboard */
{
SysKeyboardImpl *This;
HRESULT hr;
if (riid == NULL)
;/* nothing */
@ -319,10 +323,9 @@ static HRESULT keyboarddev_create_device(IDirectInputImpl *dinput, REFGUID rguid
return DIERR_NOINTERFACE;
}
This = alloc_device(rguid, dinput);
TRACE("Created a Keyboard device (%p)\n", This);
if (FAILED(hr = alloc_device( rguid, dinput, &This ))) return hr;
if (!This) return DIERR_OUTOFMEMORY;
TRACE( "Created a Keyboard device (%p)\n", This );
if (unicode)
*pdev = &This->base.IDirectInputDevice8W_iface;

View file

@ -184,7 +184,7 @@ static HRESULT mousedev_enum_deviceW(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEI
return S_FALSE;
}
static SysMouseImpl *alloc_device(REFGUID rguid, IDirectInputImpl *dinput)
static HRESULT alloc_device( REFGUID rguid, IDirectInputImpl *dinput, SysMouseImpl **out )
{
SysMouseImpl* newDevice;
LPDIDATAFORMAT df = NULL;
@ -193,7 +193,8 @@ static SysMouseImpl *alloc_device(REFGUID rguid, IDirectInputImpl *dinput)
HKEY hkey, appkey;
newDevice = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(SysMouseImpl));
if (!newDevice) return NULL;
if (!newDevice) return DIERR_OUTOFMEMORY;
newDevice->base.IDirectInputDevice8A_iface.lpVtbl = &SysMouseAvt;
newDevice->base.IDirectInputDevice8W_iface.lpVtbl = &SysMouseWvt;
newDevice->base.ref = 1;
@ -237,13 +238,14 @@ static SysMouseImpl *alloc_device(REFGUID rguid, IDirectInputImpl *dinput)
newDevice->base.raw_device.usUsage = 2; /* HID generic mouse */
}
return newDevice;
*out = newDevice;
return DI_OK;
failed:
if (df) HeapFree(GetProcessHeap(), 0, df->rgodf);
HeapFree(GetProcessHeap(), 0, df);
HeapFree(GetProcessHeap(), 0, newDevice);
return NULL;
return DIERR_OUTOFMEMORY;
}
static HRESULT mousedev_create_device(IDirectInputImpl *dinput, REFGUID rguid, REFIID riid, LPVOID *pdev, int unicode)
@ -254,6 +256,7 @@ static HRESULT mousedev_create_device(IDirectInputImpl *dinput, REFGUID rguid, R
if (IsEqualGUID(&GUID_SysMouse, rguid)) /* Wine Mouse */
{
SysMouseImpl *This;
HRESULT hr;
if (riid == NULL)
;/* nothing */
@ -277,10 +280,9 @@ static HRESULT mousedev_create_device(IDirectInputImpl *dinput, REFGUID rguid, R
return DIERR_NOINTERFACE;
}
This = alloc_device(rguid, dinput);
TRACE("Created a Mouse device (%p)\n", This);
if (FAILED(hr = alloc_device( rguid, dinput, &This ))) return hr;
if (!This) return DIERR_OUTOFMEMORY;
TRACE( "Created a Mouse device (%p)\n", This );
if (unicode)
*pdev = &This->base.IDirectInputDevice8W_iface;