Commit 324c76f3 authored by Andrew Nguyen's avatar Andrew Nguyen Committed by Alexandre Julliard

dinput: Improve the behavior of IDirectInput::CreateDevice.

parent 26932c84
......@@ -581,61 +581,48 @@ static HRESULT WINAPI IDirectInput2WImpl_FindDevice(LPDIRECTINPUT7W iface, REFGU
return DI_OK;
}
static HRESULT WINAPI IDirectInput7AImpl_CreateDeviceEx(LPDIRECTINPUT7A iface, REFGUID rguid,
REFIID riid, LPVOID* pvOut, LPUNKNOWN lpUnknownOuter)
static HRESULT create_device(IDirectInputImpl *This, REFGUID rguid, REFIID riid, LPVOID *pvOut, BOOL unicode)
{
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);
unsigned int i;
if (!rguid || !pvOut) return E_POINTER;
if (pvOut)
*pvOut = NULL;
/* Loop on all the devices to see if anyone matches the given GUID */
for (i = 0; i < NB_DINPUT_DEVICES; i++) {
HRESULT ret;
if (!rguid || !pvOut)
return E_POINTER;
if (!dinput_devices[i]->create_device) continue;
if ((ret = dinput_devices[i]->create_device(This, rguid, riid, pvOut, 0)) == DI_OK)
return DI_OK;
/* Loop on all the devices to see if anyone matches the given GUID */
for (i = 0; i < NB_DINPUT_DEVICES; i++)
{
HRESULT ret;
if (ret == DIERR_NOINTERFACE)
ret_value = DIERR_NOINTERFACE;
}
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 (ret_value == DIERR_NOINTERFACE)
{
WARN("invalid device GUID %s\n", debugstr_guid(rguid));
}
return ret_value;
return DIERR_DEVICENOTREG;
}
static HRESULT WINAPI IDirectInput7WImpl_CreateDeviceEx(LPDIRECTINPUT7W iface, REFGUID rguid,
REFIID riid, LPVOID* pvOut, LPUNKNOWN lpUnknownOuter)
static HRESULT WINAPI IDirectInput7AImpl_CreateDeviceEx(LPDIRECTINPUT7A 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);
IDirectInputImpl *This = impl_from_IDirectInput7A( iface );
if (!rguid || !pvOut) return E_POINTER;
TRACE("(%p)->(%s, %s, %p, %p)\n", This, debugstr_guid(rguid), debugstr_guid(riid), pvOut, lpUnknownOuter);
/* Loop on all the devices to see if anyone matches the given GUID */
for (i = 0; i < NB_DINPUT_DEVICES; i++) {
HRESULT ret;
return create_device(This, rguid, riid, pvOut, FALSE);
}
if (!dinput_devices[i]->create_device) continue;
if ((ret = dinput_devices[i]->create_device(This, rguid, riid, pvOut, 1)) == DI_OK)
return DI_OK;
static HRESULT WINAPI IDirectInput7WImpl_CreateDeviceEx(LPDIRECTINPUT7W iface, REFGUID rguid,
REFIID riid, LPVOID* pvOut, LPUNKNOWN lpUnknownOuter)
{
IDirectInputImpl *This = impl_from_IDirectInput7W( iface );
if (ret == DIERR_NOINTERFACE)
ret_value = DIERR_NOINTERFACE;
}
TRACE("(%p)->(%s, %s, %p, %p)\n", This, debugstr_guid(rguid), debugstr_guid(riid), pvOut, lpUnknownOuter);
return ret_value;
return create_device(This, rguid, riid, pvOut, TRUE);
}
static HRESULT WINAPI IDirectInputAImpl_CreateDevice(LPDIRECTINPUT7A iface, REFGUID rguid,
......
......@@ -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();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment