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:
Rémi Bernon 2021-05-31 10:23:55 +02:00 committed by Alexandre Julliard
parent 96ab7b4430
commit 17958bc863
7 changed files with 36 additions and 168 deletions

View File

@ -644,9 +644,15 @@ static HRESULT WINAPI IDirectInput2WImpl_FindDevice(LPDIRECTINPUT7W iface, REFGU
return DI_OK; 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; unsigned int i;
HRESULT hr;
TRACE( "(%p)->(%s, %s, %p, %p)\n", This, debugstr_guid( rguid ), debugstr_guid( riid ), pvOut, lpUnknownOuter );
if (pvOut) if (pvOut)
*pvOut = NULL; *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 */ /* Loop on all the devices to see if anyone matches the given GUID */
for (i = 0; i < ARRAY_SIZE(dinput_devices); i++) for (i = 0; i < ARRAY_SIZE(dinput_devices); i++)
{ {
HRESULT ret;
if (!dinput_devices[i]->create_device) continue; if (!dinput_devices[i]->create_device) continue;
if ((ret = dinput_devices[i]->create_device(This, rguid, riid, pvOut, unicode)) == DI_OK) if (SUCCEEDED(hr = dinput_devices[i]->create_device( This, rguid, &device )))
return DI_OK; {
hr = IDirectInputDevice8_QueryInterface( device, riid, pvOut );
IDirectInputDevice8_Release( device );
return hr;
}
} }
WARN("invalid device GUID %s\n", debugstr_guid(rguid)); WARN("invalid device GUID %s\n", debugstr_guid(rguid));
return DIERR_DEVICENOTREG; 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, static HRESULT WINAPI IDirectInputWImpl_CreateDevice(LPDIRECTINPUT7W iface, REFGUID rguid,
LPDIRECTINPUTDEVICEW* pdev, LPUNKNOWN punk) 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) LPDIRECTINPUTDEVICE8W* pdev, LPUNKNOWN punk)
{ {
IDirectInputImpl *This = impl_from_IDirectInput8W( iface ); 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, static HRESULT WINAPI IDirectInput8WImpl_EnumDevices(LPDIRECTINPUT8W iface, DWORD dwDevType, LPDIENUMDEVICESCALLBACKW lpCallback,

View File

@ -57,7 +57,7 @@ struct dinput_device {
const char *name; const char *name;
HRESULT (*enum_deviceA)(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEA lpddi, DWORD version, int id); 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 (*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 { struct DevicePlayer {

View File

@ -587,13 +587,13 @@ static unsigned short get_joystick_index(REFGUID guid)
return MAX_JOYSTICKS; 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; 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(); find_joystick_devices();
*pdev = NULL; *out = NULL;
if ((index = get_joystick_index(rguid)) < MAX_JOYSTICKS && if ((index = get_joystick_index(rguid)) < MAX_JOYSTICKS &&
joystick_devices_count && index < joystick_devices_count) joystick_devices_count && index < joystick_devices_count)
@ -601,37 +601,11 @@ static HRESULT joydev_create_device(IDirectInputImpl *dinput, REFGUID rguid, REF
JoystickImpl *This; JoystickImpl *This;
HRESULT hr; 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; if (FAILED(hr = alloc_device( rguid, dinput, &This, index ))) return hr;
TRACE( "Created a Joystick device (%p)\n", This ); TRACE( "Created a Joystick device (%p)\n", This );
if (unicode) *out = &This->generic.base.IDirectInputDevice8W_iface;
*pdev = &This->generic.base.IDirectInputDevice8W_iface;
else
*pdev = &This->generic.base.IDirectInputDevice8A_iface;
return hr; return hr;
} }

View File

@ -612,13 +612,13 @@ static unsigned short get_joystick_index(REFGUID guid)
return MAX_JOYDEV; 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; 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(); find_joydevs();
*pdev = NULL; *out = NULL;
if ((index = get_joystick_index(rguid)) < MAX_JOYDEV && if ((index = get_joystick_index(rguid)) < MAX_JOYDEV &&
have_joydevs && index < have_joydevs) have_joydevs && index < have_joydevs)
@ -626,37 +626,11 @@ static HRESULT joydev_create_device(IDirectInputImpl *dinput, REFGUID rguid, REF
JoystickImpl *This; JoystickImpl *This;
HRESULT hr; 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; if (FAILED(hr = alloc_device( rguid, dinput, &This, index ))) return hr;
TRACE( "Created a Joystick device (%p)\n", This ); TRACE( "Created a Joystick device (%p)\n", This );
if (unicode) *out = &This->generic.base.IDirectInputDevice8W_iface;
*pdev = &This->generic.base.IDirectInputDevice8W_iface;
else
*pdev = &This->generic.base.IDirectInputDevice8A_iface;
return DI_OK; return DI_OK;
} }

View File

@ -1323,13 +1323,13 @@ static unsigned short get_joystick_index(REFGUID guid)
return 0xffff; 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; unsigned short index;
int joystick_devices_count; int joystick_devices_count;
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 );
*pdev = NULL; *out = NULL;
if ((joystick_devices_count = find_joystick_devices()) == 0) if ((joystick_devices_count = find_joystick_devices()) == 0)
return DIERR_DEVICENOTREG; return DIERR_DEVICENOTREG;
@ -1340,36 +1340,11 @@ static HRESULT joydev_create_device(IDirectInputImpl *dinput, REFGUID rguid, REF
JoystickImpl *This; JoystickImpl *This;
HRESULT hr; 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; if (FAILED(hr = alloc_device( rguid, dinput, &This, index ))) return hr;
TRACE( "Created a Joystick device (%p)\n", This ); TRACE( "Created a Joystick device (%p)\n", This );
if (unicode) *out = &This->generic.base.IDirectInputDevice8W_iface;
*pdev = &This->generic.base.IDirectInputDevice8W_iface;
else
*pdev = &This->generic.base.IDirectInputDevice8A_iface;
return hr; return hr;
} }

View File

@ -283,48 +283,21 @@ failed:
return DIERR_OUTOFMEMORY; return DIERR_OUTOFMEMORY;
} }
static HRESULT keyboarddev_create_device( IDirectInputImpl *dinput, REFGUID rguid, IDirectInputDevice8W **out )
static HRESULT keyboarddev_create_device(IDirectInputImpl *dinput, REFGUID rguid, REFIID riid, LPVOID *pdev, int unicode)
{ {
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 );
*pdev = NULL; *out = NULL;
if (IsEqualGUID(&GUID_SysKeyboard, rguid)) /* Wine Keyboard */ if (IsEqualGUID(&GUID_SysKeyboard, rguid)) /* Wine Keyboard */
{ {
SysKeyboardImpl *This; SysKeyboardImpl *This;
HRESULT hr; 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; if (FAILED(hr = alloc_device( rguid, dinput, &This ))) return hr;
TRACE( "Created a Keyboard device (%p)\n", This ); TRACE( "Created a Keyboard device (%p)\n", This );
if (unicode) *out = &This->base.IDirectInputDevice8W_iface;
*pdev = &This->base.IDirectInputDevice8W_iface;
else
*pdev = &This->base.IDirectInputDevice8A_iface;
return DI_OK; return DI_OK;
} }

View File

@ -240,47 +240,21 @@ failed:
return DIERR_OUTOFMEMORY; 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); TRACE( "%p %s %p\n", dinput, debugstr_guid( rguid ), out );
*pdev = NULL; *out = NULL;
if (IsEqualGUID(&GUID_SysMouse, rguid)) /* Wine Mouse */ if (IsEqualGUID(&GUID_SysMouse, rguid)) /* Wine Mouse */
{ {
SysMouseImpl *This; SysMouseImpl *This;
HRESULT hr; 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; if (FAILED(hr = alloc_device( rguid, dinput, &This ))) return hr;
TRACE( "Created a Mouse device (%p)\n", This ); TRACE( "Created a Mouse device (%p)\n", This );
if (unicode) *out = &This->base.IDirectInputDevice8W_iface;
*pdev = &This->base.IDirectInputDevice8W_iface;
else
*pdev = &This->base.IDirectInputDevice8A_iface;
return DI_OK; return DI_OK;
} }