Vitaliy Margolen : dinput:
Keyboard should be acquired before calling GetDeviceState.
Alexandre Julliard
julliard at wine.codeweavers.com
Mon Apr 3 05:33:57 CDT 2006
Module: wine
Branch: refs/heads/master
Commit: bc1440699c071f7fa8d34ef3c65f4653653e3c6d
URL: http://source.winehq.org/git/?p=wine.git;a=commit;h=bc1440699c071f7fa8d34ef3c65f4653653e3c6d
Author: Vitaliy Margolen <wine-patch at kievinfo.com>
Date: Sat Apr 1 19:55:00 2006 -0700
dinput: Keyboard should be acquired before calling GetDeviceState.
---
dlls/dinput/keyboard.c | 3 ++-
dlls/dinput/tests/keyboard.c | 41 +++++++++++++++++++++++++++++++++++++++--
2 files changed, 41 insertions(+), 3 deletions(-)
diff --git a/dlls/dinput/keyboard.c b/dlls/dinput/keyboard.c
index 9d6ea8c..03f84c0 100644
--- a/dlls/dinput/keyboard.c
+++ b/dlls/dinput/keyboard.c
@@ -369,7 +369,8 @@ static HRESULT WINAPI SysKeyboardAImpl_G
SysKeyboardImpl *This = (SysKeyboardImpl *)iface;
TRACE("(%p)->(%ld,%p)\n", This, len, ptr);
- /* Note: device does not need to be acquired */
+ if (This->acquired == 0) return DIERR_NOTACQUIRED;
+
if (len != WINE_DINPUT_KEYBOARD_MAX_KEYS)
return DIERR_INVALIDPARAM;
diff --git a/dlls/dinput/tests/keyboard.c b/dlls/dinput/tests/keyboard.c
index dc11f9b..f2a932c 100644
--- a/dlls/dinput/tests/keyboard.c
+++ b/dlls/dinput/tests/keyboard.c
@@ -66,8 +66,45 @@ const char * get_file_version(const char
return version;
}
-static void keyboard_tests(void)
+static void keyboard_tests(DWORD version)
{
+ HRESULT hr;
+ LPDIRECTINPUT pDI;
+ LPDIRECTINPUTDEVICE pKeyboard;
+ HINSTANCE hInstance = GetModuleHandle(NULL);
+ BYTE kbd_state[256];
+ ULONG ref;
+
+ hr = DirectInputCreate(hInstance, version, &pDI, NULL);
+ ok(SUCCEEDED(hr), "DirectInputCreate() failed: %s\n", DXGetErrorString8(hr));
+ if (FAILED(hr)) return;
+
+
+ hr = IDirectInput_CreateDevice(pDI, &GUID_SysKeyboard, &pKeyboard, NULL);
+ ok(SUCCEEDED(hr), "IDirectInput_CreateDevice() failed: %s\n", DXGetErrorString8(hr));
+ if (FAILED(hr))
+ {
+ IDirectInput_Release(pDI);
+ return;
+ }
+
+ hr = IDirectInputDevice_SetDataFormat(pKeyboard, &c_dfDIKeyboard);
+ ok(SUCCEEDED(hr), "IDirectInputDevice_SetDataFormat() failed: %s\n", DXGetErrorString8(hr));
+ hr = IDirectInputDevice_SetCooperativeLevel(pKeyboard, NULL, DISCL_NONEXCLUSIVE | DISCL_BACKGROUND);
+ ok(SUCCEEDED(hr), "IDirectInputDevice_SetCooperativeLevel() failed: %s\n", DXGetErrorString8(hr));
+ hr = IDirectInputDevice_GetDeviceState(pKeyboard, 10, kbd_state);
+ ok(hr == DIERR_NOTACQUIRED, "IDirectInputDevice_GetDeviceState(10,) should have failed: %s\n", DXGetErrorString8(hr));
+ hr = IDirectInputDevice_GetDeviceState(pKeyboard, sizeof(kbd_state), kbd_state);
+ ok(hr == DIERR_NOTACQUIRED, "IDirectInputDevice_GetDeviceState() should have failed: %s\n", DXGetErrorString8(hr));
+ hr = IDirectInputDevice_Acquire(pKeyboard);
+ ok(SUCCEEDED(hr), "IDirectInputDevice_Acquire() failed: %s\n", DXGetErrorString8(hr));
+ hr = IDirectInputDevice_GetDeviceState(pKeyboard, 10, kbd_state);
+ ok(hr == DIERR_INVALIDPARAM, "IDirectInputDevice_GetDeviceState(10,) should have failed: %s\n", DXGetErrorString8(hr));
+ hr = IDirectInputDevice_GetDeviceState(pKeyboard, sizeof(kbd_state), kbd_state);
+ ok(SUCCEEDED(hr), "IDirectInputDevice_GetDeviceState() failed: %s\n", DXGetErrorString8(hr));
+
+ ref = IDirectInput_Release(pDI);
+ ok(!ref, "IDirectInput_Release() reference count = %ld\n", ref);
}
START_TEST(keyboard)
@@ -76,7 +113,7 @@ START_TEST(keyboard)
trace("DLL Version: %s\n", get_file_version("dinput.dll"));
- keyboard_tests();
+ keyboard_tests(0x0700);
CoUninitialize();
}
More information about the wine-cvs
mailing list