dinput: Improve the behavior of IDirectInput::CreateDevice.
This commit is contained in:
parent
26932c84b0
commit
324c76f386
|
@ -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 (pvOut)
|
||||||
|
*pvOut = NULL;
|
||||||
|
|
||||||
if (!rguid || !pvOut) return E_POINTER;
|
if (!rguid || !pvOut)
|
||||||
|
return E_POINTER;
|
||||||
|
|
||||||
/* Loop on all the devices to see if anyone matches the given GUID */
|
/* Loop on all the devices to see if anyone matches the given GUID */
|
||||||
for (i = 0; i < NB_DINPUT_DEVICES; i++) {
|
for (i = 0; i < NB_DINPUT_DEVICES; i++)
|
||||||
HRESULT ret;
|
{
|
||||||
|
HRESULT ret;
|
||||||
|
|
||||||
if (!dinput_devices[i]->create_device) continue;
|
if (!dinput_devices[i]->create_device) continue;
|
||||||
if ((ret = dinput_devices[i]->create_device(This, rguid, riid, pvOut, 0)) == DI_OK)
|
if ((ret = dinput_devices[i]->create_device(This, rguid, riid, pvOut, unicode)) == DI_OK)
|
||||||
return 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));
|
WARN("invalid device GUID %s\n", debugstr_guid(rguid));
|
||||||
}
|
return DIERR_DEVICENOTREG;
|
||||||
|
}
|
||||||
|
|
||||||
return ret_value;
|
static HRESULT WINAPI IDirectInput7AImpl_CreateDeviceEx(LPDIRECTINPUT7A iface, REFGUID rguid,
|
||||||
|
REFIID riid, LPVOID* pvOut, LPUNKNOWN lpUnknownOuter)
|
||||||
|
{
|
||||||
|
IDirectInputImpl *This = impl_from_IDirectInput7A( iface );
|
||||||
|
|
||||||
|
TRACE("(%p)->(%s, %s, %p, %p)\n", This, debugstr_guid(rguid), debugstr_guid(riid), pvOut, lpUnknownOuter);
|
||||||
|
|
||||||
|
return create_device(This, rguid, riid, pvOut, FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static HRESULT WINAPI IDirectInput7WImpl_CreateDeviceEx(LPDIRECTINPUT7W iface, REFGUID rguid,
|
static HRESULT WINAPI IDirectInput7WImpl_CreateDeviceEx(LPDIRECTINPUT7W 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_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);
|
TRACE("(%p)->(%s, %s, %p, %p)\n", This, debugstr_guid(rguid), debugstr_guid(riid), pvOut, lpUnknownOuter);
|
||||||
|
|
||||||
if (!rguid || !pvOut) return E_POINTER;
|
return create_device(This, rguid, riid, pvOut, TRUE);
|
||||||
|
|
||||||
/* 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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
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)
|
||||||
|
|
||||||
CoInitialize(NULL);
|
CoInitialize(NULL);
|
||||||
test_QueryInterface();
|
test_QueryInterface();
|
||||||
|
test_CreateDevice();
|
||||||
test_Initialize();
|
test_Initialize();
|
||||||
test_RunControlPanel();
|
test_RunControlPanel();
|
||||||
CoUninitialize();
|
CoUninitialize();
|
||||||
|
|
Loading…
Reference in New Issue