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:
parent
e79fa1866c
commit
ad8e3727c1
|
@ -451,8 +451,7 @@ static HRESULT joydev_enum_deviceW(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINS
|
||||||
return S_FALSE;
|
return S_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static HRESULT alloc_device(REFGUID rguid, IDirectInputImpl *dinput,
|
static HRESULT alloc_device( REFGUID rguid, IDirectInputImpl *dinput, JoystickImpl **out, unsigned short index )
|
||||||
JoystickImpl **pdev, unsigned short index)
|
|
||||||
{
|
{
|
||||||
DWORD i;
|
DWORD i;
|
||||||
JoystickImpl* newDevice;
|
JoystickImpl* newDevice;
|
||||||
|
@ -461,14 +460,10 @@ static HRESULT alloc_device(REFGUID rguid, IDirectInputImpl *dinput,
|
||||||
int idx = 0;
|
int idx = 0;
|
||||||
DIDEVICEINSTANCEW ddi;
|
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));
|
newDevice = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(JoystickImpl));
|
||||||
if (newDevice == 0) {
|
if (!newDevice) return DIERR_OUTOFMEMORY;
|
||||||
WARN("out of memory\n");
|
|
||||||
*pdev = 0;
|
|
||||||
return DIERR_OUTOFMEMORY;
|
|
||||||
}
|
|
||||||
|
|
||||||
newDevice->joydev = &joystick_devices[index];
|
newDevice->joydev = &joystick_devices[index];
|
||||||
newDevice->joyfd = -1;
|
newDevice->joyfd = -1;
|
||||||
|
@ -564,8 +559,7 @@ static HRESULT alloc_device(REFGUID rguid, IDirectInputImpl *dinput,
|
||||||
_dump_DIDEVCAPS(&newDevice->generic.devcaps);
|
_dump_DIDEVCAPS(&newDevice->generic.devcaps);
|
||||||
}
|
}
|
||||||
|
|
||||||
*pdev = newDevice;
|
*out = newDevice;
|
||||||
|
|
||||||
return DI_OK;
|
return DI_OK;
|
||||||
|
|
||||||
FAILED:
|
FAILED:
|
||||||
|
@ -576,8 +570,6 @@ FAILED1:
|
||||||
release_DataFormat(&newDevice->generic.base.data_format);
|
release_DataFormat(&newDevice->generic.base.data_format);
|
||||||
HeapFree(GetProcessHeap(),0,newDevice->generic.axis_map);
|
HeapFree(GetProcessHeap(),0,newDevice->generic.axis_map);
|
||||||
HeapFree(GetProcessHeap(),0,newDevice);
|
HeapFree(GetProcessHeap(),0,newDevice);
|
||||||
*pdev = 0;
|
|
||||||
|
|
||||||
return hr;
|
return hr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -641,8 +633,9 @@ static HRESULT joydev_create_device(IDirectInputImpl *dinput, REFGUID rguid, REF
|
||||||
return DIERR_NOINTERFACE;
|
return DIERR_NOINTERFACE;
|
||||||
}
|
}
|
||||||
|
|
||||||
hr = alloc_device(rguid, dinput, &This, index);
|
if (FAILED(hr = alloc_device( rguid, dinput, &This, index ))) return hr;
|
||||||
if (!This) return hr;
|
|
||||||
|
TRACE( "Created a Joystick device (%p)\n", This );
|
||||||
|
|
||||||
if (unicode)
|
if (unicode)
|
||||||
*pdev = &This->generic.base.IDirectInputDevice8W_iface;
|
*pdev = &This->generic.base.IDirectInputDevice8W_iface;
|
||||||
|
|
|
@ -444,7 +444,7 @@ static HRESULT joydev_enum_deviceW(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINS
|
||||||
return S_FALSE;
|
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;
|
JoystickImpl* newDevice;
|
||||||
LPDIDATAFORMAT df = NULL;
|
LPDIDATAFORMAT df = NULL;
|
||||||
|
@ -453,7 +453,7 @@ static JoystickImpl *alloc_device(REFGUID rguid, IDirectInputImpl *dinput, unsig
|
||||||
DIDEVICEINSTANCEW ddi;
|
DIDEVICEINSTANCEW ddi;
|
||||||
|
|
||||||
newDevice = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(JoystickImpl));
|
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.IDirectInputDevice8A_iface.lpVtbl = &JoystickAvt;
|
||||||
newDevice->generic.base.IDirectInputDevice8W_iface.lpVtbl = &JoystickWvt;
|
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);
|
IDirectInput_AddRef(&newDevice->generic.base.dinput->IDirectInput7A_iface);
|
||||||
|
|
||||||
return newDevice;
|
*out = newDevice;
|
||||||
|
return DI_OK;
|
||||||
|
|
||||||
failed:
|
failed:
|
||||||
if (df) HeapFree(GetProcessHeap(), 0, df->rgodf);
|
if (df) HeapFree(GetProcessHeap(), 0, df->rgodf);
|
||||||
HeapFree(GetProcessHeap(), 0, df);
|
HeapFree(GetProcessHeap(), 0, df);
|
||||||
HeapFree(GetProcessHeap(), 0, newDevice->generic.axis_map);
|
HeapFree(GetProcessHeap(), 0, newDevice->generic.axis_map);
|
||||||
HeapFree(GetProcessHeap(), 0, newDevice);
|
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)
|
have_joydevs && index < have_joydevs)
|
||||||
{
|
{
|
||||||
JoystickImpl *This;
|
JoystickImpl *This;
|
||||||
|
HRESULT hr;
|
||||||
|
|
||||||
if (riid == NULL)
|
if (riid == NULL)
|
||||||
;/* nothing */
|
;/* nothing */
|
||||||
|
@ -653,10 +655,9 @@ static HRESULT joydev_create_device(IDirectInputImpl *dinput, REFGUID rguid, REF
|
||||||
return DIERR_NOINTERFACE;
|
return DIERR_NOINTERFACE;
|
||||||
}
|
}
|
||||||
|
|
||||||
This = alloc_device(rguid, dinput, index);
|
if (FAILED(hr = alloc_device( rguid, dinput, &This, index ))) return hr;
|
||||||
TRACE("Created a Joystick device (%p)\n", This);
|
|
||||||
|
|
||||||
if (!This) return DIERR_OUTOFMEMORY;
|
TRACE( "Created a Joystick device (%p)\n", This );
|
||||||
|
|
||||||
if (unicode)
|
if (unicode)
|
||||||
*pdev = &This->generic.base.IDirectInputDevice8W_iface;
|
*pdev = &This->generic.base.IDirectInputDevice8W_iface;
|
||||||
|
|
|
@ -1105,8 +1105,7 @@ static BOOL osx_axis_has_ff(FFCAPABILITIES *ffcaps, UInt8 axis)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static HRESULT alloc_device(REFGUID rguid, IDirectInputImpl *dinput,
|
static HRESULT alloc_device( REFGUID rguid, IDirectInputImpl *dinput, JoystickImpl **out, unsigned short index )
|
||||||
JoystickImpl **pdev, unsigned short index)
|
|
||||||
{
|
{
|
||||||
DWORD i;
|
DWORD i;
|
||||||
IOHIDDeviceRef device;
|
IOHIDDeviceRef device;
|
||||||
|
@ -1119,14 +1118,10 @@ static HRESULT alloc_device(REFGUID rguid, IDirectInputImpl *dinput,
|
||||||
int slider_count = 0;
|
int slider_count = 0;
|
||||||
FFCAPABILITIES ffcaps;
|
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));
|
newDevice = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(JoystickImpl));
|
||||||
if (newDevice == 0) {
|
if (!newDevice) return DIERR_OUTOFMEMORY;
|
||||||
WARN("out of memory\n");
|
|
||||||
*pdev = 0;
|
|
||||||
return DIERR_OUTOFMEMORY;
|
|
||||||
}
|
|
||||||
|
|
||||||
newDevice->id = index;
|
newDevice->id = index;
|
||||||
|
|
||||||
|
@ -1287,8 +1282,7 @@ static HRESULT alloc_device(REFGUID rguid, IDirectInputImpl *dinput,
|
||||||
_dump_DIDEVCAPS(&newDevice->generic.devcaps);
|
_dump_DIDEVCAPS(&newDevice->generic.devcaps);
|
||||||
}
|
}
|
||||||
|
|
||||||
*pdev = newDevice;
|
*out = newDevice;
|
||||||
|
|
||||||
return DI_OK;
|
return DI_OK;
|
||||||
|
|
||||||
FAILED:
|
FAILED:
|
||||||
|
@ -1300,8 +1294,6 @@ FAILED:
|
||||||
release_DataFormat(&newDevice->generic.base.data_format);
|
release_DataFormat(&newDevice->generic.base.data_format);
|
||||||
HeapFree(GetProcessHeap(),0,newDevice->generic.name);
|
HeapFree(GetProcessHeap(),0,newDevice->generic.name);
|
||||||
HeapFree(GetProcessHeap(),0,newDevice);
|
HeapFree(GetProcessHeap(),0,newDevice);
|
||||||
*pdev = 0;
|
|
||||||
|
|
||||||
return hr;
|
return hr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1380,8 +1372,9 @@ static HRESULT joydev_create_device(IDirectInputImpl *dinput, REFGUID rguid, REF
|
||||||
return DIERR_NOINTERFACE;
|
return DIERR_NOINTERFACE;
|
||||||
}
|
}
|
||||||
|
|
||||||
hr = alloc_device(rguid, dinput, &This, index);
|
if (FAILED(hr = alloc_device( rguid, dinput, &This, index ))) return hr;
|
||||||
if (!This) return hr;
|
|
||||||
|
TRACE( "Created a Joystick device (%p)\n", This );
|
||||||
|
|
||||||
if (unicode)
|
if (unicode)
|
||||||
*pdev = &This->generic.base.IDirectInputDevice8W_iface;
|
*pdev = &This->generic.base.IDirectInputDevice8W_iface;
|
||||||
|
|
|
@ -240,13 +240,15 @@ static HRESULT keyboarddev_enum_deviceW(DWORD dwDevType, DWORD dwFlags, LPDIDEVI
|
||||||
return S_FALSE;
|
return S_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static SysKeyboardImpl *alloc_device(REFGUID rguid, IDirectInputImpl *dinput)
|
static HRESULT alloc_device( REFGUID rguid, IDirectInputImpl *dinput, SysKeyboardImpl **out )
|
||||||
{
|
{
|
||||||
SysKeyboardImpl* newDevice;
|
SysKeyboardImpl* newDevice;
|
||||||
LPDIDATAFORMAT df = NULL;
|
LPDIDATAFORMAT df = NULL;
|
||||||
int i, idx = 0;
|
int i, idx = 0;
|
||||||
|
|
||||||
newDevice = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(SysKeyboardImpl));
|
newDevice = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(SysKeyboardImpl));
|
||||||
|
if (!newDevice) return DIERR_OUTOFMEMORY;
|
||||||
|
|
||||||
newDevice->base.IDirectInputDevice8A_iface.lpVtbl = &SysKeyboardAvt;
|
newDevice->base.IDirectInputDevice8A_iface.lpVtbl = &SysKeyboardAvt;
|
||||||
newDevice->base.IDirectInputDevice8W_iface.lpVtbl = &SysKeyboardWvt;
|
newDevice->base.IDirectInputDevice8W_iface.lpVtbl = &SysKeyboardWvt;
|
||||||
newDevice->base.ref = 1;
|
newDevice->base.ref = 1;
|
||||||
|
@ -278,13 +280,14 @@ static SysKeyboardImpl *alloc_device(REFGUID rguid, IDirectInputImpl *dinput)
|
||||||
newDevice->base.data_format.wine_df = df;
|
newDevice->base.data_format.wine_df = df;
|
||||||
IDirectInput_AddRef(&newDevice->base.dinput->IDirectInput7A_iface);
|
IDirectInput_AddRef(&newDevice->base.dinput->IDirectInput7A_iface);
|
||||||
|
|
||||||
return newDevice;
|
*out = newDevice;
|
||||||
|
return DI_OK;
|
||||||
|
|
||||||
failed:
|
failed:
|
||||||
if (df) HeapFree(GetProcessHeap(), 0, df->rgodf);
|
if (df) HeapFree(GetProcessHeap(), 0, df->rgodf);
|
||||||
HeapFree(GetProcessHeap(), 0, df);
|
HeapFree(GetProcessHeap(), 0, df);
|
||||||
HeapFree(GetProcessHeap(), 0, newDevice);
|
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 */
|
if (IsEqualGUID(&GUID_SysKeyboard, rguid)) /* Wine Keyboard */
|
||||||
{
|
{
|
||||||
SysKeyboardImpl *This;
|
SysKeyboardImpl *This;
|
||||||
|
HRESULT hr;
|
||||||
|
|
||||||
if (riid == NULL)
|
if (riid == NULL)
|
||||||
;/* nothing */
|
;/* nothing */
|
||||||
|
@ -319,10 +323,9 @@ static HRESULT keyboarddev_create_device(IDirectInputImpl *dinput, REFGUID rguid
|
||||||
return DIERR_NOINTERFACE;
|
return DIERR_NOINTERFACE;
|
||||||
}
|
}
|
||||||
|
|
||||||
This = alloc_device(rguid, dinput);
|
if (FAILED(hr = alloc_device( rguid, dinput, &This ))) return hr;
|
||||||
TRACE("Created a Keyboard device (%p)\n", This);
|
|
||||||
|
|
||||||
if (!This) return DIERR_OUTOFMEMORY;
|
TRACE( "Created a Keyboard device (%p)\n", This );
|
||||||
|
|
||||||
if (unicode)
|
if (unicode)
|
||||||
*pdev = &This->base.IDirectInputDevice8W_iface;
|
*pdev = &This->base.IDirectInputDevice8W_iface;
|
||||||
|
|
|
@ -184,7 +184,7 @@ static HRESULT mousedev_enum_deviceW(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEI
|
||||||
return S_FALSE;
|
return S_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static SysMouseImpl *alloc_device(REFGUID rguid, IDirectInputImpl *dinput)
|
static HRESULT alloc_device( REFGUID rguid, IDirectInputImpl *dinput, SysMouseImpl **out )
|
||||||
{
|
{
|
||||||
SysMouseImpl* newDevice;
|
SysMouseImpl* newDevice;
|
||||||
LPDIDATAFORMAT df = NULL;
|
LPDIDATAFORMAT df = NULL;
|
||||||
|
@ -193,7 +193,8 @@ static SysMouseImpl *alloc_device(REFGUID rguid, IDirectInputImpl *dinput)
|
||||||
HKEY hkey, appkey;
|
HKEY hkey, appkey;
|
||||||
|
|
||||||
newDevice = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(SysMouseImpl));
|
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.IDirectInputDevice8A_iface.lpVtbl = &SysMouseAvt;
|
||||||
newDevice->base.IDirectInputDevice8W_iface.lpVtbl = &SysMouseWvt;
|
newDevice->base.IDirectInputDevice8W_iface.lpVtbl = &SysMouseWvt;
|
||||||
newDevice->base.ref = 1;
|
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 */
|
newDevice->base.raw_device.usUsage = 2; /* HID generic mouse */
|
||||||
}
|
}
|
||||||
|
|
||||||
return newDevice;
|
*out = newDevice;
|
||||||
|
return DI_OK;
|
||||||
|
|
||||||
failed:
|
failed:
|
||||||
if (df) HeapFree(GetProcessHeap(), 0, df->rgodf);
|
if (df) HeapFree(GetProcessHeap(), 0, df->rgodf);
|
||||||
HeapFree(GetProcessHeap(), 0, df);
|
HeapFree(GetProcessHeap(), 0, df);
|
||||||
HeapFree(GetProcessHeap(), 0, newDevice);
|
HeapFree(GetProcessHeap(), 0, newDevice);
|
||||||
return NULL;
|
return DIERR_OUTOFMEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
static HRESULT mousedev_create_device(IDirectInputImpl *dinput, REFGUID rguid, REFIID riid, LPVOID *pdev, int unicode)
|
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 */
|
if (IsEqualGUID(&GUID_SysMouse, rguid)) /* Wine Mouse */
|
||||||
{
|
{
|
||||||
SysMouseImpl *This;
|
SysMouseImpl *This;
|
||||||
|
HRESULT hr;
|
||||||
|
|
||||||
if (riid == NULL)
|
if (riid == NULL)
|
||||||
;/* nothing */
|
;/* nothing */
|
||||||
|
@ -277,10 +280,9 @@ static HRESULT mousedev_create_device(IDirectInputImpl *dinput, REFGUID rguid, R
|
||||||
return DIERR_NOINTERFACE;
|
return DIERR_NOINTERFACE;
|
||||||
}
|
}
|
||||||
|
|
||||||
This = alloc_device(rguid, dinput);
|
if (FAILED(hr = alloc_device( rguid, dinput, &This ))) return hr;
|
||||||
TRACE("Created a Mouse device (%p)\n", This);
|
|
||||||
|
|
||||||
if (!This) return DIERR_OUTOFMEMORY;
|
TRACE( "Created a Mouse device (%p)\n", This );
|
||||||
|
|
||||||
if (unicode)
|
if (unicode)
|
||||||
*pdev = &This->base.IDirectInputDevice8W_iface;
|
*pdev = &This->base.IDirectInputDevice8W_iface;
|
||||||
|
|
Loading…
Reference in New Issue