dinput: Factor out device creation interface queries.
Signed-off-by: Rémi Bernon <rbernon@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
parent
96ab7b4430
commit
17958bc863
|
@ -644,9 +644,15 @@ static HRESULT WINAPI IDirectInput2WImpl_FindDevice(LPDIRECTINPUT7W iface, REFGU
|
|||
return DI_OK;
|
||||
}
|
||||
|
||||
static HRESULT create_device(IDirectInputImpl *This, REFGUID rguid, REFIID riid, LPVOID *pvOut, BOOL unicode)
|
||||
static HRESULT WINAPI IDirectInput7WImpl_CreateDeviceEx( IDirectInput7W *iface, REFGUID rguid, REFIID riid,
|
||||
LPVOID *pvOut, LPUNKNOWN lpUnknownOuter )
|
||||
{
|
||||
IDirectInputDevice8W *device;
|
||||
IDirectInputImpl *This = impl_from_IDirectInput7W( iface );
|
||||
unsigned int i;
|
||||
HRESULT hr;
|
||||
|
||||
TRACE( "(%p)->(%s, %s, %p, %p)\n", This, debugstr_guid( rguid ), debugstr_guid( riid ), pvOut, lpUnknownOuter );
|
||||
|
||||
if (pvOut)
|
||||
*pvOut = NULL;
|
||||
|
@ -660,31 +666,23 @@ static HRESULT create_device(IDirectInputImpl *This, REFGUID rguid, REFIID riid,
|
|||
/* Loop on all the devices to see if anyone matches the given GUID */
|
||||
for (i = 0; i < ARRAY_SIZE(dinput_devices); i++)
|
||||
{
|
||||
HRESULT ret;
|
||||
|
||||
if (!dinput_devices[i]->create_device) continue;
|
||||
if ((ret = dinput_devices[i]->create_device(This, rguid, riid, pvOut, unicode)) == DI_OK)
|
||||
return DI_OK;
|
||||
if (SUCCEEDED(hr = dinput_devices[i]->create_device( This, rguid, &device )))
|
||||
{
|
||||
hr = IDirectInputDevice8_QueryInterface( device, riid, pvOut );
|
||||
IDirectInputDevice8_Release( device );
|
||||
return hr;
|
||||
}
|
||||
}
|
||||
|
||||
WARN("invalid device GUID %s\n", debugstr_guid(rguid));
|
||||
return DIERR_DEVICENOTREG;
|
||||
}
|
||||
|
||||
static HRESULT WINAPI IDirectInput7WImpl_CreateDeviceEx(LPDIRECTINPUT7W iface, REFGUID rguid,
|
||||
REFIID riid, LPVOID* pvOut, LPUNKNOWN lpUnknownOuter)
|
||||
{
|
||||
IDirectInputImpl *This = impl_from_IDirectInput7W( iface );
|
||||
|
||||
TRACE("(%p)->(%s, %s, %p, %p)\n", This, debugstr_guid(rguid), debugstr_guid(riid), pvOut, lpUnknownOuter);
|
||||
|
||||
return create_device(This, rguid, riid, pvOut, TRUE);
|
||||
}
|
||||
|
||||
static HRESULT WINAPI IDirectInputWImpl_CreateDevice(LPDIRECTINPUT7W iface, REFGUID rguid,
|
||||
LPDIRECTINPUTDEVICEW* pdev, LPUNKNOWN punk)
|
||||
{
|
||||
return IDirectInput7_CreateDeviceEx( iface, rguid, NULL, (LPVOID *)pdev, punk );
|
||||
return IDirectInput7_CreateDeviceEx( iface, rguid, &IID_IDirectInputDeviceW, (LPVOID *)pdev, punk );
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
|
@ -713,7 +711,7 @@ static HRESULT WINAPI IDirectInput8WImpl_CreateDevice(LPDIRECTINPUT8W iface, REF
|
|||
LPDIRECTINPUTDEVICE8W* pdev, LPUNKNOWN punk)
|
||||
{
|
||||
IDirectInputImpl *This = impl_from_IDirectInput8W( iface );
|
||||
return IDirectInput7_CreateDeviceEx( &This->IDirectInput7W_iface, rguid, NULL, (LPVOID *)pdev, punk );
|
||||
return IDirectInput7_CreateDeviceEx( &This->IDirectInput7W_iface, rguid, &IID_IDirectInputDevice8W, (LPVOID *)pdev, punk );
|
||||
}
|
||||
|
||||
static HRESULT WINAPI IDirectInput8WImpl_EnumDevices(LPDIRECTINPUT8W iface, DWORD dwDevType, LPDIENUMDEVICESCALLBACKW lpCallback,
|
||||
|
|
|
@ -57,7 +57,7 @@ struct dinput_device {
|
|||
const char *name;
|
||||
HRESULT (*enum_deviceA)(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEA lpddi, DWORD version, int id);
|
||||
HRESULT (*enum_deviceW)(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEW lpddi, DWORD version, int id);
|
||||
HRESULT (*create_device)(IDirectInputImpl *dinput, REFGUID rguid, REFIID riid, LPVOID *pdev, int unicode);
|
||||
HRESULT (*create_device)(IDirectInputImpl *dinput, REFGUID rguid, IDirectInputDevice8W **out);
|
||||
};
|
||||
|
||||
struct DevicePlayer {
|
||||
|
|
|
@ -587,13 +587,13 @@ static unsigned short get_joystick_index(REFGUID guid)
|
|||
return MAX_JOYSTICKS;
|
||||
}
|
||||
|
||||
static HRESULT joydev_create_device(IDirectInputImpl *dinput, REFGUID rguid, REFIID riid, LPVOID *pdev, int unicode)
|
||||
static HRESULT joydev_create_device( IDirectInputImpl *dinput, REFGUID rguid, IDirectInputDevice8W **out )
|
||||
{
|
||||
unsigned short index;
|
||||
|
||||
TRACE("%p %s %s %p %i\n", dinput, debugstr_guid(rguid), debugstr_guid(riid), pdev, unicode);
|
||||
TRACE( "%p %s %p\n", dinput, debugstr_guid( rguid ), out );
|
||||
find_joystick_devices();
|
||||
*pdev = NULL;
|
||||
*out = NULL;
|
||||
|
||||
if ((index = get_joystick_index(rguid)) < MAX_JOYSTICKS &&
|
||||
joystick_devices_count && index < joystick_devices_count)
|
||||
|
@ -601,37 +601,11 @@ static HRESULT joydev_create_device(IDirectInputImpl *dinput, REFGUID rguid, REF
|
|||
JoystickImpl *This;
|
||||
HRESULT hr;
|
||||
|
||||
if (riid == NULL)
|
||||
;/* nothing */
|
||||
else if (IsEqualGUID(&IID_IDirectInputDeviceA, riid) ||
|
||||
IsEqualGUID(&IID_IDirectInputDevice2A, riid) ||
|
||||
IsEqualGUID(&IID_IDirectInputDevice7A, riid) ||
|
||||
IsEqualGUID(&IID_IDirectInputDevice8A, riid))
|
||||
{
|
||||
unicode = 0;
|
||||
}
|
||||
else if (IsEqualGUID(&IID_IDirectInputDeviceW, riid) ||
|
||||
IsEqualGUID(&IID_IDirectInputDevice2W, riid) ||
|
||||
IsEqualGUID(&IID_IDirectInputDevice7W, riid) ||
|
||||
IsEqualGUID(&IID_IDirectInputDevice8W, riid))
|
||||
{
|
||||
unicode = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
WARN("no interface\n");
|
||||
return DIERR_NOINTERFACE;
|
||||
}
|
||||
|
||||
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;
|
||||
else
|
||||
*pdev = &This->generic.base.IDirectInputDevice8A_iface;
|
||||
|
||||
*out = &This->generic.base.IDirectInputDevice8W_iface;
|
||||
return hr;
|
||||
}
|
||||
|
||||
|
|
|
@ -612,13 +612,13 @@ static unsigned short get_joystick_index(REFGUID guid)
|
|||
return MAX_JOYDEV;
|
||||
}
|
||||
|
||||
static HRESULT joydev_create_device(IDirectInputImpl *dinput, REFGUID rguid, REFIID riid, LPVOID *pdev, int unicode)
|
||||
static HRESULT joydev_create_device( IDirectInputImpl *dinput, REFGUID rguid, IDirectInputDevice8W **out )
|
||||
{
|
||||
unsigned short index;
|
||||
|
||||
TRACE("%p %s %s %p %i\n", dinput, debugstr_guid(rguid), debugstr_guid(riid), pdev, unicode);
|
||||
TRACE( "%p %s %p\n", dinput, debugstr_guid( rguid ), out );
|
||||
find_joydevs();
|
||||
*pdev = NULL;
|
||||
*out = NULL;
|
||||
|
||||
if ((index = get_joystick_index(rguid)) < MAX_JOYDEV &&
|
||||
have_joydevs && index < have_joydevs)
|
||||
|
@ -626,37 +626,11 @@ static HRESULT joydev_create_device(IDirectInputImpl *dinput, REFGUID rguid, REF
|
|||
JoystickImpl *This;
|
||||
HRESULT hr;
|
||||
|
||||
if (riid == NULL)
|
||||
;/* nothing */
|
||||
else if (IsEqualGUID(&IID_IDirectInputDeviceA, riid) ||
|
||||
IsEqualGUID(&IID_IDirectInputDevice2A, riid) ||
|
||||
IsEqualGUID(&IID_IDirectInputDevice7A, riid) ||
|
||||
IsEqualGUID(&IID_IDirectInputDevice8A, riid))
|
||||
{
|
||||
unicode = 0;
|
||||
}
|
||||
else if (IsEqualGUID(&IID_IDirectInputDeviceW, riid) ||
|
||||
IsEqualGUID(&IID_IDirectInputDevice2W, riid) ||
|
||||
IsEqualGUID(&IID_IDirectInputDevice7W, riid) ||
|
||||
IsEqualGUID(&IID_IDirectInputDevice8W, riid))
|
||||
{
|
||||
unicode = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
WARN("no interface\n");
|
||||
return DIERR_NOINTERFACE;
|
||||
}
|
||||
|
||||
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;
|
||||
else
|
||||
*pdev = &This->generic.base.IDirectInputDevice8A_iface;
|
||||
|
||||
*out = &This->generic.base.IDirectInputDevice8W_iface;
|
||||
return DI_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -1323,13 +1323,13 @@ static unsigned short get_joystick_index(REFGUID guid)
|
|||
return 0xffff;
|
||||
}
|
||||
|
||||
static HRESULT joydev_create_device(IDirectInputImpl *dinput, REFGUID rguid, REFIID riid, LPVOID *pdev, int unicode)
|
||||
static HRESULT joydev_create_device( IDirectInputImpl *dinput, REFGUID rguid, IDirectInputDevice8W **out )
|
||||
{
|
||||
unsigned short index;
|
||||
int joystick_devices_count;
|
||||
|
||||
TRACE("%p %s %s %p %i\n", dinput, debugstr_guid(rguid), debugstr_guid(riid), pdev, unicode);
|
||||
*pdev = NULL;
|
||||
TRACE( "%p %s %p\n", dinput, debugstr_guid( rguid ), out );
|
||||
*out = NULL;
|
||||
|
||||
if ((joystick_devices_count = find_joystick_devices()) == 0)
|
||||
return DIERR_DEVICENOTREG;
|
||||
|
@ -1340,36 +1340,11 @@ static HRESULT joydev_create_device(IDirectInputImpl *dinput, REFGUID rguid, REF
|
|||
JoystickImpl *This;
|
||||
HRESULT hr;
|
||||
|
||||
if (riid == NULL)
|
||||
;/* nothing */
|
||||
else if (IsEqualGUID(&IID_IDirectInputDeviceA, riid) ||
|
||||
IsEqualGUID(&IID_IDirectInputDevice2A, riid) ||
|
||||
IsEqualGUID(&IID_IDirectInputDevice7A, riid) ||
|
||||
IsEqualGUID(&IID_IDirectInputDevice8A, riid))
|
||||
{
|
||||
unicode = 0;
|
||||
}
|
||||
else if (IsEqualGUID(&IID_IDirectInputDeviceW, riid) ||
|
||||
IsEqualGUID(&IID_IDirectInputDevice2W, riid) ||
|
||||
IsEqualGUID(&IID_IDirectInputDevice7W, riid) ||
|
||||
IsEqualGUID(&IID_IDirectInputDevice8W, riid))
|
||||
{
|
||||
unicode = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
WARN("no interface\n");
|
||||
return DIERR_NOINTERFACE;
|
||||
}
|
||||
|
||||
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;
|
||||
else
|
||||
*pdev = &This->generic.base.IDirectInputDevice8A_iface;
|
||||
*out = &This->generic.base.IDirectInputDevice8W_iface;
|
||||
return hr;
|
||||
}
|
||||
|
||||
|
|
|
@ -283,48 +283,21 @@ failed:
|
|||
return DIERR_OUTOFMEMORY;
|
||||
}
|
||||
|
||||
|
||||
static HRESULT keyboarddev_create_device(IDirectInputImpl *dinput, REFGUID rguid, REFIID riid, LPVOID *pdev, int unicode)
|
||||
static HRESULT keyboarddev_create_device( IDirectInputImpl *dinput, REFGUID rguid, IDirectInputDevice8W **out )
|
||||
{
|
||||
TRACE("%p %s %s %p %i\n", dinput, debugstr_guid(rguid), debugstr_guid(riid), pdev, unicode);
|
||||
*pdev = NULL;
|
||||
TRACE( "%p %s %p\n", dinput, debugstr_guid( rguid ), out );
|
||||
*out = NULL;
|
||||
|
||||
if (IsEqualGUID(&GUID_SysKeyboard, rguid)) /* Wine Keyboard */
|
||||
{
|
||||
SysKeyboardImpl *This;
|
||||
HRESULT hr;
|
||||
|
||||
if (riid == NULL)
|
||||
;/* nothing */
|
||||
else if (IsEqualGUID(&IID_IDirectInputDeviceA, riid) ||
|
||||
IsEqualGUID(&IID_IDirectInputDevice2A, riid) ||
|
||||
IsEqualGUID(&IID_IDirectInputDevice7A, riid) ||
|
||||
IsEqualGUID(&IID_IDirectInputDevice8A, riid))
|
||||
{
|
||||
unicode = 0;
|
||||
}
|
||||
else if (IsEqualGUID(&IID_IDirectInputDeviceW, riid) ||
|
||||
IsEqualGUID(&IID_IDirectInputDevice2W, riid) ||
|
||||
IsEqualGUID(&IID_IDirectInputDevice7W, riid) ||
|
||||
IsEqualGUID(&IID_IDirectInputDevice8W, riid))
|
||||
{
|
||||
unicode = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
WARN("no interface\n");
|
||||
return DIERR_NOINTERFACE;
|
||||
}
|
||||
|
||||
if (FAILED(hr = alloc_device( rguid, dinput, &This ))) return hr;
|
||||
|
||||
TRACE( "Created a Keyboard device (%p)\n", This );
|
||||
|
||||
if (unicode)
|
||||
*pdev = &This->base.IDirectInputDevice8W_iface;
|
||||
else
|
||||
*pdev = &This->base.IDirectInputDevice8A_iface;
|
||||
|
||||
*out = &This->base.IDirectInputDevice8W_iface;
|
||||
return DI_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -240,47 +240,21 @@ failed:
|
|||
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, IDirectInputDevice8W **out )
|
||||
{
|
||||
TRACE("%p %s %s %p %i\n", dinput, debugstr_guid(rguid), debugstr_guid(riid), pdev, unicode);
|
||||
*pdev = NULL;
|
||||
TRACE( "%p %s %p\n", dinput, debugstr_guid( rguid ), out );
|
||||
*out = NULL;
|
||||
|
||||
if (IsEqualGUID(&GUID_SysMouse, rguid)) /* Wine Mouse */
|
||||
{
|
||||
SysMouseImpl *This;
|
||||
HRESULT hr;
|
||||
|
||||
if (riid == NULL)
|
||||
;/* nothing */
|
||||
else if (IsEqualGUID(&IID_IDirectInputDeviceA, riid) ||
|
||||
IsEqualGUID(&IID_IDirectInputDevice2A, riid) ||
|
||||
IsEqualGUID(&IID_IDirectInputDevice7A, riid) ||
|
||||
IsEqualGUID(&IID_IDirectInputDevice8A, riid))
|
||||
{
|
||||
unicode = 0;
|
||||
}
|
||||
else if (IsEqualGUID(&IID_IDirectInputDeviceW, riid) ||
|
||||
IsEqualGUID(&IID_IDirectInputDevice2W, riid) ||
|
||||
IsEqualGUID(&IID_IDirectInputDevice7W, riid) ||
|
||||
IsEqualGUID(&IID_IDirectInputDevice8W, riid))
|
||||
{
|
||||
unicode = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
WARN("no interface\n");
|
||||
return DIERR_NOINTERFACE;
|
||||
}
|
||||
|
||||
if (FAILED(hr = alloc_device( rguid, dinput, &This ))) return hr;
|
||||
|
||||
TRACE( "Created a Mouse device (%p)\n", This );
|
||||
|
||||
if (unicode)
|
||||
*pdev = &This->base.IDirectInputDevice8W_iface;
|
||||
else
|
||||
*pdev = &This->base.IDirectInputDevice8A_iface;
|
||||
|
||||
*out = &This->base.IDirectInputDevice8W_iface;
|
||||
return DI_OK;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue