dinput: Don't try to create non existing device.

This commit is contained in:
Vitaliy Margolen 2007-08-19 22:26:19 -06:00 committed by Alexandre Julliard
parent 55b63fe095
commit f47c63a1f9
1 changed files with 41 additions and 28 deletions

View File

@ -505,24 +505,31 @@ static HRESULT joydev_create_deviceA(IDirectInputImpl *dinput, REFGUID rguid, RE
find_joydevs(); find_joydevs();
if ((index = get_joystick_index(rguid)) < MAX_JOYDEV) { if ((index = get_joystick_index(rguid)) < MAX_JOYDEV &&
have_joydevs && index < have_joydevs)
{
if ((riid == NULL) || if ((riid == NULL) ||
IsEqualGUID(&IID_IDirectInputDeviceA,riid) || IsEqualGUID(&IID_IDirectInputDeviceA, riid) ||
IsEqualGUID(&IID_IDirectInputDevice2A,riid) || IsEqualGUID(&IID_IDirectInputDevice2A, riid) ||
IsEqualGUID(&IID_IDirectInputDevice7A,riid) || IsEqualGUID(&IID_IDirectInputDevice7A, riid) ||
IsEqualGUID(&IID_IDirectInputDevice8A,riid)) { IsEqualGUID(&IID_IDirectInputDevice8A, riid))
{
*pdev = (IDirectInputDeviceA*) alloc_device(rguid, &JoystickAvt, dinput, index); *pdev = (IDirectInputDeviceA*) alloc_device(rguid, &JoystickAvt, dinput, index);
TRACE("Creating a Joystick device (%p)\n", *pdev); TRACE("Created a Joystick device (%p)\n", *pdev);
if (*pdev==0) {
if (*pdev == NULL)
{
ERR("out of memory\n"); ERR("out of memory\n");
return DIERR_OUTOFMEMORY; return DIERR_OUTOFMEMORY;
} }
return DI_OK; return DI_OK;
} else {
return DIERR_NOINTERFACE;
}
} }
WARN("no interface\n");
return DIERR_NOINTERFACE;
}
WARN("invalid device GUID\n");
return DIERR_DEVICENOTREG; return DIERR_DEVICENOTREG;
} }
@ -533,24 +540,30 @@ static HRESULT joydev_create_deviceW(IDirectInputImpl *dinput, REFGUID rguid, RE
find_joydevs(); find_joydevs();
if ((index = get_joystick_index(rguid)) < MAX_JOYDEV) { if ((index = get_joystick_index(rguid)) < MAX_JOYDEV &&
have_joydevs && index < have_joydevs)
{
if ((riid == NULL) || if ((riid == NULL) ||
IsEqualGUID(&IID_IDirectInputDeviceW,riid) || IsEqualGUID(&IID_IDirectInputDeviceW, riid) ||
IsEqualGUID(&IID_IDirectInputDevice2W,riid) || IsEqualGUID(&IID_IDirectInputDevice2W, riid) ||
IsEqualGUID(&IID_IDirectInputDevice7W,riid) || IsEqualGUID(&IID_IDirectInputDevice7W, riid) ||
IsEqualGUID(&IID_IDirectInputDevice8W,riid)) { IsEqualGUID(&IID_IDirectInputDevice8W, riid))
{
*pdev = (IDirectInputDeviceW*) alloc_device(rguid, &JoystickWvt, dinput, index); *pdev = (IDirectInputDeviceW*) alloc_device(rguid, &JoystickWvt, dinput, index);
TRACE("Creating a Joystick device (%p)\n", *pdev); TRACE("Created a Joystick device (%p)\n", *pdev);
if (*pdev==0) {
if (*pdev == NULL)
{
ERR("out of memory\n"); ERR("out of memory\n");
return DIERR_OUTOFMEMORY; return DIERR_OUTOFMEMORY;
} }
return DI_OK; return DI_OK;
} else { }
WARN("no interface\n");
return DIERR_NOINTERFACE; return DIERR_NOINTERFACE;
} }
}
WARN("invalid device GUID\n");
return DIERR_DEVICENOTREG; return DIERR_DEVICENOTREG;
} }