diff --git a/dlls/dinput/dinput_main.c b/dlls/dinput/dinput_main.c index 3493bdd440a..865da02b5d7 100644 --- a/dlls/dinput/dinput_main.c +++ b/dlls/dinput/dinput_main.c @@ -421,6 +421,9 @@ static HRESULT WINAPI IDirectInputAImpl_QueryInterface(LPDIRECTINPUT7A iface, RE TRACE( "(%p)->(%s,%p)\n", This, debugstr_guid(riid), ppobj ); + if (!riid || !ppobj) + return E_POINTER; + if (IsEqualGUID( &IID_IUnknown, riid ) || IsEqualGUID( &IID_IDirectInputA, riid ) || IsEqualGUID( &IID_IDirectInput2A, riid ) || @@ -459,7 +462,8 @@ static HRESULT WINAPI IDirectInputAImpl_QueryInterface(LPDIRECTINPUT7A iface, RE } FIXME( "Unsupported interface: %s\n", debugstr_guid(riid)); - return E_FAIL; + *ppobj = NULL; + return E_NOINTERFACE; } static HRESULT WINAPI IDirectInputWImpl_QueryInterface(LPDIRECTINPUT7W iface, REFIID riid, LPVOID *ppobj) diff --git a/dlls/dinput/tests/device.c b/dlls/dinput/tests/device.c index a8ff19be93d..ea25482e591 100644 --- a/dlls/dinput/tests/device.c +++ b/dlls/dinput/tests/device.c @@ -23,7 +23,6 @@ #include "wine/test.h" #include "windef.h" -#include "initguid.h" #include "dinput.h" static const DIOBJECTDATAFORMAT obj_data_format[] = { diff --git a/dlls/dinput/tests/dinput.c b/dlls/dinput/tests/dinput.c index 71ed4f68516..7b25b8a8a69 100644 --- a/dlls/dinput/tests/dinput.c +++ b/dlls/dinput/tests/dinput.c @@ -19,6 +19,7 @@ #define DIRECTINPUT_VERSION 0x0700 #define COBJMACROS +#include #include #include @@ -26,6 +27,86 @@ HINSTANCE hInstance; +static void test_QueryInterface(void) +{ + static const REFIID iid_list[] = {&IID_IUnknown, &IID_IDirectInputA, &IID_IDirectInputW, + &IID_IDirectInput2A, &IID_IDirectInput2W, + &IID_IDirectInput7A, &IID_IDirectInput7W}; + + static const struct + { + REFIID riid; + int test_todo; + } no_interface_list[] = + { + {&IID_IDirectInput8A, 1}, + {&IID_IDirectInput8W, 1}, + {&IID_IDirectInputDeviceA}, + {&IID_IDirectInputDeviceW}, + {&IID_IDirectInputDevice2A}, + {&IID_IDirectInputDevice2W}, + {&IID_IDirectInputDevice7A}, + {&IID_IDirectInputDevice7W}, + {&IID_IDirectInputDevice8A}, + {&IID_IDirectInputDevice8W}, + {&IID_IDirectInputEffect}, + }; + + IDirectInputA *pDI; + HRESULT hr; + IUnknown *pUnk; + int i; + + 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_QueryInterface(pDI, NULL, NULL); + ok(hr == E_POINTER, "IDirectInput_QueryInterface returned 0x%08x\n", hr); + + pUnk = (void *)0xdeadbeef; + hr = IDirectInput_QueryInterface(pDI, NULL, (void **)&pUnk); + ok(hr == E_POINTER, "IDirectInput_QueryInterface returned 0x%08x\n", hr); + ok(pUnk == (void *)0xdeadbeef, "Output interface pointer is %p\n", pUnk); + + hr = IDirectInput_QueryInterface(pDI, &IID_IUnknown, NULL); + ok(hr == E_POINTER, "IDirectInput_QueryInterface returned 0x%08x\n", hr); + + for (i = 0; i < sizeof(iid_list)/sizeof(iid_list[0]); i++) + { + pUnk = NULL; + hr = IDirectInput_QueryInterface(pDI, iid_list[i], (void **)&pUnk); + ok(hr == S_OK, "[%d] IDirectInput_QueryInterface returned 0x%08x\n", i, hr); + ok(pUnk != NULL, "[%d] Output interface pointer is NULL\n", i); + if (pUnk) IUnknown_Release(pUnk); + } + + for (i = 0; i < sizeof(no_interface_list)/sizeof(no_interface_list[0]); i++) + { + pUnk = (void *)0xdeadbeef; + hr = IDirectInput_QueryInterface(pDI, no_interface_list[i].riid, (void **)&pUnk); + if (no_interface_list[i].test_todo) + { + todo_wine + ok(hr == E_NOINTERFACE, "[%d] IDirectInput_QueryInterface returned 0x%08x\n", i, hr); + todo_wine + ok(pUnk == NULL, "[%d] Output interface pointer is %p\n", i, pUnk); + + if (pUnk) IUnknown_Release(pUnk); + } + else + { + ok(hr == E_NOINTERFACE, "[%d] IDirectInput_QueryInterface returned 0x%08x\n", i, hr); + ok(pUnk == NULL, "[%d] Output interface pointer is %p\n", i, pUnk); + } + } + + IDirectInput_Release(pDI); +} + static void test_RunControlPanel(void) { IDirectInputA *pDI; @@ -64,6 +145,7 @@ START_TEST(dinput) hInstance = GetModuleHandleA(NULL); CoInitialize(NULL); + test_QueryInterface(); test_RunControlPanel(); CoUninitialize(); }