dinput: Improve the behavior of IDirectInput::CreateDevice.

This commit is contained in:
Andrew Nguyen 2011-07-05 07:19:01 -05:00 committed by Alexandre Julliard
parent 26932c84b0
commit 324c76f386
2 changed files with 68 additions and 41 deletions

View File

@ -581,61 +581,48 @@ 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)
{
unsigned int i;
if (pvOut)
*pvOut = NULL;
if (!rguid || !pvOut)
return E_POINTER;
/* Loop on all the devices to see if anyone matches the given GUID */
for (i = 0; i < NB_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;
}
WARN("invalid device GUID %s\n", debugstr_guid(rguid));
return DIERR_DEVICENOTREG;
}
static HRESULT WINAPI IDirectInput7AImpl_CreateDeviceEx(LPDIRECTINPUT7A iface, REFGUID rguid,
REFIID riid, LPVOID* pvOut, LPUNKNOWN lpUnknownOuter)
{
IDirectInputImpl *This = impl_from_IDirectInput7A( iface );
HRESULT ret_value = DIERR_DEVICENOTREG;
unsigned int i;
TRACE("(%p)->(%s, %s, %p, %p)\n", This, debugstr_guid(rguid), debugstr_guid(riid), pvOut, lpUnknownOuter);
if (!rguid || !pvOut) return E_POINTER;
/* Loop on all the devices to see if anyone matches the given GUID */
for (i = 0; i < NB_DINPUT_DEVICES; i++) {
HRESULT ret;
if (!dinput_devices[i]->create_device) continue;
if ((ret = dinput_devices[i]->create_device(This, rguid, riid, pvOut, 0)) == DI_OK)
return DI_OK;
if (ret == DIERR_NOINTERFACE)
ret_value = DIERR_NOINTERFACE;
}
if (ret_value == DIERR_NOINTERFACE)
{
WARN("invalid device GUID %s\n", debugstr_guid(rguid));
}
return ret_value;
return create_device(This, rguid, riid, pvOut, FALSE);
}
static HRESULT WINAPI IDirectInput7WImpl_CreateDeviceEx(LPDIRECTINPUT7W iface, REFGUID rguid,
REFIID riid, LPVOID* pvOut, LPUNKNOWN lpUnknownOuter)
{
IDirectInputImpl *This = impl_from_IDirectInput7W( iface );
HRESULT ret_value = DIERR_DEVICENOTREG;
unsigned int i;
TRACE("(%p)->(%s, %s, %p, %p)\n", This, debugstr_guid(rguid), debugstr_guid(riid), pvOut, lpUnknownOuter);
if (!rguid || !pvOut) return E_POINTER;
/* Loop on all the devices to see if anyone matches the given GUID */
for (i = 0; i < NB_DINPUT_DEVICES; i++) {
HRESULT ret;
if (!dinput_devices[i]->create_device) continue;
if ((ret = dinput_devices[i]->create_device(This, rguid, riid, pvOut, 1)) == DI_OK)
return DI_OK;
if (ret == DIERR_NOINTERFACE)
ret_value = DIERR_NOINTERFACE;
}
return ret_value;
return create_device(This, rguid, riid, pvOut, TRUE);
}
static HRESULT WINAPI IDirectInputAImpl_CreateDevice(LPDIRECTINPUT7A iface, REFGUID rguid,

View File

@ -129,6 +129,45 @@ static void test_QueryInterface(void)
IDirectInput_Release(pDI);
}
static void test_CreateDevice(void)
{
IDirectInputA *pDI;
HRESULT hr;
IDirectInputDeviceA *pDID;
hr = DirectInputCreateA(hInstance, DIRECTINPUT_VERSION, &pDI, NULL);
if (FAILED(hr))
{
win_skip("Failed to instantiate a IDirectInputA instance: 0x%08x\n", hr);
return;
}
hr = IDirectInput_CreateDevice(pDI, NULL, NULL, NULL);
ok(hr == E_POINTER, "IDirectInput_CreateDevice returned 0x%08x\n", hr);
pDID = (void *)0xdeadbeef;
hr = IDirectInput_CreateDevice(pDI, NULL, &pDID, NULL);
ok(hr == E_POINTER, "IDirectInput_CreateDevice returned 0x%08x\n", hr);
ok(pDID == NULL, "Output interface pointer is %p\n", pDID);
hr = IDirectInput_CreateDevice(pDI, &GUID_Unknown, NULL, NULL);
ok(hr == E_POINTER, "IDirectInput_CreateDevice returned 0x%08x\n", hr);
pDID = (void *)0xdeadbeef;
hr = IDirectInput_CreateDevice(pDI, &GUID_Unknown, &pDID, NULL);
ok(hr == DIERR_DEVICENOTREG, "IDirectInput_CreateDevice returned 0x%08x\n", hr);
ok(pDID == NULL, "Output interface pointer is %p\n", pDID);
hr = IDirectInput_CreateDevice(pDI, &GUID_SysMouse, NULL, NULL);
ok(hr == E_POINTER, "IDirectInput_CreateDevice returned 0x%08x\n", hr);
hr = IDirectInput_CreateDevice(pDI, &GUID_SysMouse, &pDID, NULL);
ok(hr == DI_OK, "IDirectInput_CreateDevice returned 0x%08x\n", hr);
IDirectInputDevice_Release(pDID);
IDirectInput_Release(pDI);
}
static void test_Initialize(void)
{
IDirectInputA *pDI;
@ -211,6 +250,7 @@ START_TEST(dinput)
CoInitialize(NULL);
test_QueryInterface();
test_CreateDevice();
test_Initialize();
test_RunControlPanel();
CoUninitialize();