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 ...@@ -581,61 +581,48 @@ static HRESULT WINAPI IDirectInput2WImpl_FindDevice(LPDIRECTINPUT7W iface, REFGU
return DI_OK; return DI_OK;
} }
static HRESULT WINAPI IDirectInput7AImpl_CreateDeviceEx(LPDIRECTINPUT7A iface, REFGUID rguid, static HRESULT create_device(IDirectInputImpl *This, REFGUID rguid, REFIID riid, LPVOID *pvOut, BOOL unicode)
REFIID riid, LPVOID* pvOut, LPUNKNOWN lpUnknownOuter)
{ {
IDirectInputImpl *This = impl_from_IDirectInput7A( iface ); unsigned int i;
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; if (pvOut)
*pvOut = NULL;
/* Loop on all the devices to see if anyone matches the given GUID */ if (!rguid || !pvOut)
for (i = 0; i < NB_DINPUT_DEVICES; i++) { return E_POINTER;
HRESULT ret;
if (!dinput_devices[i]->create_device) continue; /* Loop on all the devices to see if anyone matches the given GUID */
if ((ret = dinput_devices[i]->create_device(This, rguid, riid, pvOut, 0)) == DI_OK) for (i = 0; i < NB_DINPUT_DEVICES; i++)
return DI_OK; {
HRESULT ret;
if (ret == DIERR_NOINTERFACE) if (!dinput_devices[i]->create_device) continue;
ret_value = DIERR_NOINTERFACE; 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)); WARN("invalid device GUID %s\n", debugstr_guid(rguid));
} return DIERR_DEVICENOTREG;
return ret_value;
} }
static HRESULT WINAPI IDirectInput7WImpl_CreateDeviceEx(LPDIRECTINPUT7W iface, REFGUID rguid, static HRESULT WINAPI IDirectInput7AImpl_CreateDeviceEx(LPDIRECTINPUT7A iface, REFGUID rguid,
REFIID riid, LPVOID* pvOut, LPUNKNOWN lpUnknownOuter) REFIID riid, LPVOID* pvOut, LPUNKNOWN lpUnknownOuter)
{ {
IDirectInputImpl *This = impl_from_IDirectInput7W( iface ); 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; 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 */ return create_device(This, rguid, riid, pvOut, FALSE);
for (i = 0; i < NB_DINPUT_DEVICES; i++) { }
HRESULT ret;
if (!dinput_devices[i]->create_device) continue; static HRESULT WINAPI IDirectInput7WImpl_CreateDeviceEx(LPDIRECTINPUT7W iface, REFGUID rguid,
if ((ret = dinput_devices[i]->create_device(This, rguid, riid, pvOut, 1)) == DI_OK) REFIID riid, LPVOID* pvOut, LPUNKNOWN lpUnknownOuter)
return DI_OK; {
IDirectInputImpl *This = impl_from_IDirectInput7W( iface );
if (ret == DIERR_NOINTERFACE) TRACE("(%p)->(%s, %s, %p, %p)\n", This, debugstr_guid(rguid), debugstr_guid(riid), pvOut, lpUnknownOuter);
ret_value = DIERR_NOINTERFACE;
}
return ret_value; return create_device(This, rguid, riid, pvOut, TRUE);
} }
static HRESULT WINAPI IDirectInputAImpl_CreateDevice(LPDIRECTINPUT7A iface, REFGUID rguid, static HRESULT WINAPI IDirectInputAImpl_CreateDevice(LPDIRECTINPUT7A iface, REFGUID rguid,
......
...@@ -129,6 +129,45 @@ static void test_QueryInterface(void) ...@@ -129,6 +129,45 @@ static void test_QueryInterface(void)
IDirectInput_Release(pDI); 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) static void test_Initialize(void)
{ {
IDirectInputA *pDI; IDirectInputA *pDI;
...@@ -211,6 +250,7 @@ START_TEST(dinput) ...@@ -211,6 +250,7 @@ START_TEST(dinput)
CoInitialize(NULL); CoInitialize(NULL);
test_QueryInterface(); test_QueryInterface();
test_CreateDevice();
test_Initialize(); test_Initialize();
test_RunControlPanel(); test_RunControlPanel();
CoUninitialize(); 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