Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/user32/rawinput.c | 16 ++++++++++++++-- dlls/user32/tests/input.c | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 2 deletions(-)
diff --git a/dlls/user32/rawinput.c b/dlls/user32/rawinput.c index 1e66b394cb5..9a72a9a323e 100644 --- a/dlls/user32/rawinput.c +++ b/dlls/user32/rawinput.c @@ -696,8 +696,16 @@ UINT WINAPI GetRawInputDeviceInfoW(HANDLE handle, UINT command, void *data, UINT TRACE("handle %p, command %#x, data %p, data_size %p.\n", handle, command, data, data_size);
- if (!data_size) return ~0U; - if (!(device = find_device_from_handle(handle))) return ~0U; + if (!data_size) + { + SetLastError(ERROR_NOACCESS); + return ~0U; + } + if (!(device = find_device_from_handle(handle))) + { + SetLastError(ERROR_INVALID_HANDLE); + return ~0U; + }
/* each case below must set: * *data_size: length (meaning defined by command) of data we want to copy @@ -769,6 +777,7 @@ UINT WINAPI GetRawInputDeviceInfoW(HANDLE handle, UINT command, void *data, UINT
default: FIXME("command %#x not supported\n", command); + SetLastError(ERROR_INVALID_PARAMETER); return ~0U; }
@@ -776,7 +785,10 @@ UINT WINAPI GetRawInputDeviceInfoW(HANDLE handle, UINT command, void *data, UINT return 0;
if (avail_bytes < to_copy_bytes) + { + SetLastError(ERROR_INSUFFICIENT_BUFFER); return ~0U; + }
memcpy(data, to_copy, to_copy_bytes);
diff --git a/dlls/user32/tests/input.c b/dlls/user32/tests/input.c index 382e124e1f4..4ce2c5643cd 100644 --- a/dlls/user32/tests/input.c +++ b/dlls/user32/tests/input.c @@ -1834,6 +1834,43 @@ static void test_GetRawInputDeviceList(void) ret = pGetRawInputDeviceList(devices, &devcount, sizeof(devices[0])); ok(ret > 0, "expected non-zero\n");
+ if (devcount) + { + RID_DEVICE_INFO info; + UINT size; + + SetLastError( 0xdeadbeef ); + ret = pGetRawInputDeviceInfoW( UlongToHandle( 0xdeadbeef ), RIDI_DEVICEINFO, NULL, NULL ); + ok( ret == ~0U, "GetRawInputDeviceInfoW returned %#x, expected ~0.\n", ret ); + ok( GetLastError() == ERROR_NOACCESS, "GetRawInputDeviceInfoW last error %#x, expected 0xdeadbeef.\n", GetLastError() ); + + SetLastError( 0xdeadbeef ); + size = 0xdeadbeef; + ret = pGetRawInputDeviceInfoW( UlongToHandle( 0xdeadbeef ), RIDI_DEVICEINFO, NULL, &size ); + ok( ret == ~0U, "GetRawInputDeviceInfoW returned %#x, expected ~0.\n", ret ); + ok( size == 0xdeadbeef, "GetRawInputDeviceInfoW returned size %#x, expected 0.\n", size ); + ok( GetLastError() == ERROR_INVALID_HANDLE, "GetRawInputDeviceInfoW last error %#x, expected 0xdeadbeef.\n", GetLastError() ); + + SetLastError( 0xdeadbeef ); + size = 0xdeadbeef; + ret = pGetRawInputDeviceInfoW( devices[0].hDevice, 0xdeadbeef, NULL, &size ); + ok( ret == ~0U, "GetRawInputDeviceInfoW returned %#x, expected ~0.\n", ret ); + ok( size == 0xdeadbeef, "GetRawInputDeviceInfoW returned size %#x, expected 0.\n", size ); + ok( GetLastError() == ERROR_INVALID_PARAMETER, "GetRawInputDeviceInfoW last error %#x, expected 0xdeadbeef.\n", GetLastError() ); + + SetLastError( 0xdeadbeef ); + ret = pGetRawInputDeviceInfoW( devices[0].hDevice, RIDI_DEVICEINFO, &info, NULL ); + ok( ret == ~0U, "GetRawInputDeviceInfoW returned %#x, expected ~0.\n", ret ); + ok( GetLastError() == ERROR_NOACCESS, "GetRawInputDeviceInfoW last error %#x, expected 0xdeadbeef.\n", GetLastError() ); + + SetLastError( 0xdeadbeef ); + size = 0; + ret = pGetRawInputDeviceInfoW( devices[0].hDevice, RIDI_DEVICEINFO, &info, &size ); + ok( ret == ~0U, "GetRawInputDeviceInfoW returned %#x, expected ~0.\n", ret ); + ok( size == sizeof(info), "GetRawInputDeviceInfoW returned size %#x, expected %#x.\n", size, sizeof(info) ); + ok( GetLastError() == ERROR_INSUFFICIENT_BUFFER, "GetRawInputDeviceInfoW last error %#x, expected 0xdeadbeef.\n", GetLastError() ); + } + for(i = 0; i < devcount; ++i) { WCHAR name[128];