[PATCH 2/4] win32u: Move NtUserGetRegisteredRawInputDevices from user32.
Zebediah Figura
wine at gitlab.winehq.org
Sat Jun 25 11:57:53 CDT 2022
From: Zebediah Figura <zfigura at codeweavers.com>
---
dlls/user32/rawinput.c | 57 ---------------------------------------
dlls/user32/user32.spec | 2 +-
dlls/win32u/rawinput.c | 59 +++++++++++++++++++++++++++++++++++++++++
dlls/win32u/syscall.c | 1 +
dlls/win32u/win32u.spec | 2 +-
dlls/wow64win/syscall.h | 1 +
dlls/wow64win/user.c | 41 ++++++++++++++++++++++++++++
include/ntuser.h | 1 +
8 files changed, 105 insertions(+), 59 deletions(-)
diff --git a/dlls/user32/rawinput.c b/dlls/user32/rawinput.c
index 1b02be1398d..588d1685cc0 100644
--- a/dlls/user32/rawinput.c
+++ b/dlls/user32/rawinput.c
@@ -506,63 +506,6 @@ UINT WINAPI GetRawInputDeviceInfoW(HANDLE handle, UINT command, void *data, UINT
return *data_size;
}
-static int __cdecl compare_raw_input_devices(const void *ap, const void *bp)
-{
- const RAWINPUTDEVICE a = *(const RAWINPUTDEVICE *)ap;
- const RAWINPUTDEVICE b = *(const RAWINPUTDEVICE *)bp;
-
- if (a.usUsagePage != b.usUsagePage) return a.usUsagePage - b.usUsagePage;
- if (a.usUsage != b.usUsage) return a.usUsage - b.usUsage;
- return 0;
-}
-
-/***********************************************************************
- * GetRegisteredRawInputDevices (USER32.@)
- */
-UINT WINAPI DECLSPEC_HOTPATCH GetRegisteredRawInputDevices(RAWINPUTDEVICE *devices, UINT *device_count, UINT size)
-{
- struct rawinput_device *buffer = NULL;
- unsigned int i, status, count = ~0U, buffer_size;
-
- TRACE("devices %p, device_count %p, size %u\n", devices, device_count, size);
-
- if (size != sizeof(RAWINPUTDEVICE) || !device_count || (devices && !*device_count))
- {
- SetLastError(ERROR_INVALID_PARAMETER);
- return ~0U;
- }
-
- buffer_size = *device_count * sizeof(*buffer);
- if (devices && !(buffer = HeapAlloc(GetProcessHeap(), 0, buffer_size)))
- return ~0U;
-
- SERVER_START_REQ(get_rawinput_devices)
- {
- if (buffer) wine_server_set_reply(req, buffer, buffer_size);
- status = wine_server_call_err(req);
- *device_count = reply->device_count;
- }
- SERVER_END_REQ;
-
- if (buffer && !status)
- {
- for (i = 0, count = *device_count; i < count; ++i)
- {
- devices[i].usUsagePage = buffer[i].usage_page;
- devices[i].usUsage = buffer[i].usage;
- devices[i].dwFlags = buffer[i].flags;
- devices[i].hwndTarget = wine_server_ptr_handle(buffer[i].target);
- }
-
- qsort(devices, count, sizeof(*devices), compare_raw_input_devices);
- }
-
- if (buffer) HeapFree(GetProcessHeap(), 0, buffer);
- else count = 0;
- return count;
-}
-
-
/***********************************************************************
* DefRawInputProc (USER32.@)
*/
diff --git a/dlls/user32/user32.spec b/dlls/user32/user32.spec
index dbe2a4c1430..3e20277251a 100644
--- a/dlls/user32/user32.spec
+++ b/dlls/user32/user32.spec
@@ -372,7 +372,7 @@
@ stdcall GetRawInputDeviceInfoW(ptr long ptr ptr)
@ stdcall GetRawInputDeviceList(ptr ptr long)
# @ stub GetReasonTitleFromReasonCode
-@ stdcall GetRegisteredRawInputDevices(ptr ptr long)
+@ stdcall GetRegisteredRawInputDevices(ptr ptr long) NtUserGetRegisteredRawInputDevices
@ stdcall GetScrollBarInfo(long long ptr)
@ stdcall GetScrollInfo(long long ptr)
@ stdcall GetScrollPos(long long)
diff --git a/dlls/win32u/rawinput.c b/dlls/win32u/rawinput.c
index 359faa39083..1caf11f2e76 100644
--- a/dlls/win32u/rawinput.c
+++ b/dlls/win32u/rawinput.c
@@ -427,3 +427,62 @@ BOOL WINAPI NtUserRegisterRawInputDevices( const RAWINPUTDEVICE *devices, UINT d
return ret;
}
+
+static int compare_raw_input_devices( const void *ap, const void *bp )
+{
+ const RAWINPUTDEVICE a = *(const RAWINPUTDEVICE *)ap;
+ const RAWINPUTDEVICE b = *(const RAWINPUTDEVICE *)bp;
+
+ if (a.usUsagePage != b.usUsagePage) return a.usUsagePage - b.usUsagePage;
+ if (a.usUsage != b.usUsage) return a.usUsage - b.usUsage;
+ return 0;
+}
+
+/**********************************************************************
+ * NtUserGetRegisteredRawInputDevices (win32u.@)
+ */
+UINT WINAPI NtUserGetRegisteredRawInputDevices( RAWINPUTDEVICE *devices, UINT *device_count, UINT size )
+{
+ struct rawinput_device *buffer = NULL;
+ unsigned int i, status, buffer_size;
+
+ TRACE("devices %p, device_count %p, size %u\n", devices, device_count, size);
+
+ if (size != sizeof(RAWINPUTDEVICE) || !device_count || (devices && !*device_count))
+ {
+ SetLastError( ERROR_INVALID_PARAMETER );
+ return ~0u;
+ }
+
+ buffer_size = *device_count * sizeof(*buffer);
+ if (devices && !(buffer = malloc( buffer_size )))
+ return ~0u;
+
+ SERVER_START_REQ(get_rawinput_devices)
+ {
+ if (buffer) wine_server_set_reply( req, buffer, buffer_size );
+ status = wine_server_call_err(req);
+ *device_count = reply->device_count;
+ }
+ SERVER_END_REQ;
+ if (status)
+ {
+ free( buffer );
+ return ~0u;
+ }
+
+ if (!devices) return 0;
+
+ for (i = 0; i < *device_count; ++i)
+ {
+ devices[i].usUsagePage = buffer[i].usage_page;
+ devices[i].usUsage = buffer[i].usage;
+ devices[i].dwFlags = buffer[i].flags;
+ devices[i].hwndTarget = wine_server_ptr_handle(buffer[i].target);
+ }
+
+ qsort( devices, *device_count, sizeof(*devices), compare_raw_input_devices );
+
+ free( buffer );
+ return *device_count;
+}
diff --git a/dlls/win32u/syscall.c b/dlls/win32u/syscall.c
index 3f2c596f727..49746725816 100644
--- a/dlls/win32u/syscall.c
+++ b/dlls/win32u/syscall.c
@@ -147,6 +147,7 @@ static void * const syscalls[] =
NtUserGetProp,
NtUserGetRawInputBuffer,
NtUserGetRawInputData,
+ NtUserGetRegisteredRawInputDevices,
NtUserGetSystemDpiForProcess,
NtUserGetThreadDesktop,
NtUserGetTitleBarInfo,
diff --git a/dlls/win32u/win32u.spec b/dlls/win32u/win32u.spec
index 687ef3af8dc..dab6e2a5ed8 100644
--- a/dlls/win32u/win32u.spec
+++ b/dlls/win32u/win32u.spec
@@ -988,7 +988,7 @@
@ stub NtUserGetRawInputDeviceInfo
@ stub NtUserGetRawInputDeviceList
@ stub NtUserGetRawPointerDeviceData
-@ stub NtUserGetRegisteredRawInputDevices
+@ stdcall -syscall NtUserGetRegisteredRawInputDevices(ptr ptr long)
@ stub NtUserGetRequiredCursorSizes
@ stub NtUserGetResizeDCompositionSynchronizationObject
@ stub NtUserGetScrollBarInfo
diff --git a/dlls/wow64win/syscall.h b/dlls/wow64win/syscall.h
index 531f9f7f9cd..903f146025d 100644
--- a/dlls/wow64win/syscall.h
+++ b/dlls/wow64win/syscall.h
@@ -134,6 +134,7 @@
SYSCALL_ENTRY( NtUserGetProp ) \
SYSCALL_ENTRY( NtUserGetRawInputBuffer ) \
SYSCALL_ENTRY( NtUserGetRawInputData ) \
+ SYSCALL_ENTRY( NtUserGetRegisteredRawInputDevices ) \
SYSCALL_ENTRY( NtUserGetSystemDpiForProcess ) \
SYSCALL_ENTRY( NtUserGetThreadDesktop ) \
SYSCALL_ENTRY( NtUserGetTitleBarInfo ) \
diff --git a/dlls/wow64win/user.c b/dlls/wow64win/user.c
index 5c110c7c97b..5e0d09d250a 100644
--- a/dlls/wow64win/user.c
+++ b/dlls/wow64win/user.c
@@ -1015,3 +1015,44 @@ NTSTATUS WINAPI wow64_NtUserRegisterRawInputDevices( UINT *args )
return NtUserRegisterRawInputDevices( devices64, count, sizeof(*devices64) );
}
+
+NTSTATUS WINAPI wow64_NtUserGetRegisteredRawInputDevices( UINT *args )
+{
+ RAWINPUTDEVICE *devices32 = get_ptr( &args );
+ UINT *count = get_ptr( &args );
+ UINT size = get_ulong( &args );
+
+ if (size != sizeof(RAWINPUTDEVICE32))
+ {
+ SetLastError( ERROR_INVALID_PARAMETER );
+ return FALSE;
+ }
+
+ if (devices32)
+ {
+ RAWINPUTDEVICE *devices64;
+ unsigned int ret, i;
+
+ if (!(devices64 = Wow64AllocateTemp( (*count) * sizeof(*devices64) )))
+ {
+ SetLastError( ERROR_NOT_ENOUGH_MEMORY );
+ return FALSE;
+ }
+
+ ret = NtUserGetRegisteredRawInputDevices( devices64, count, sizeof(RAWINPUTDEVICE) );
+ if (ret == ~0u) return ret;
+
+ for (i = 0; i < *count; ++i)
+ {
+ devices32[i].usUsagePage = devices64[i].usUsagePage;
+ devices32[i].usUsage = devices64[i].usUsage;
+ devices32[i].dwFlags = devices64[i].dwFlags;
+ devices32[i].hwndTarget = devices64[i].hwndTarget;
+ }
+ return ret;
+ }
+ else
+ {
+ return NtUserGetRegisteredRawInputDevices( NULL, count, sizeof(RAWINPUTDEVICE) );
+ }
+}
diff --git a/include/ntuser.h b/include/ntuser.h
index ea2f8408318..2e71f0cfb52 100644
--- a/include/ntuser.h
+++ b/include/ntuser.h
@@ -613,6 +613,7 @@ ULONG WINAPI NtUserGetProcessDpiAwarenessContext( HANDLE process );
DWORD WINAPI NtUserGetQueueStatus( UINT flags );
UINT WINAPI NtUserGetRawInputBuffer( RAWINPUT *data, UINT *data_size, UINT header_size );
UINT WINAPI NtUserGetRawInputData( HRAWINPUT rawinput, UINT command, void *data, UINT *data_size, UINT header_size );
+UINT WINAPI NtUserGetRegisteredRawInputDevices( RAWINPUTDEVICE *devices, UINT *device_count, UINT size );
ULONG WINAPI NtUserGetSystemDpiForProcess( HANDLE process );
HMENU WINAPI NtUserGetSystemMenu( HWND hwnd, BOOL revert );
HDESK WINAPI NtUserGetThreadDesktop( DWORD thread );
--
GitLab
https://gitlab.winehq.org/wine/wine/-/merge_requests/313
More information about the wine-devel
mailing list