[PATCH v2 4/5] hidclass.sys: Assign rawinput device handle in HID_LinkDevice.

Rémi Bernon rbernon at codeweavers.com
Fri Apr 9 06:11:34 CDT 2021


The handles are just numeric values and not real object handles, they
are used in the hDevice field of the RAWINPUTHEADER struct.

They will also be used as an HID rawinput device array index on the
server side.

Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=50506
Signed-off-by: Rémi Bernon <rbernon at codeweavers.com>
---
 dlls/hidclass.sys/device.c | 17 +++++++++++++++++
 dlls/hidclass.sys/hid.h    |  1 +
 2 files changed, 18 insertions(+)

diff --git a/dlls/hidclass.sys/device.c b/dlls/hidclass.sys/device.c
index fc1dfd07db1..9a3c92b3576 100644
--- a/dlls/hidclass.sys/device.c
+++ b/dlls/hidclass.sys/device.c
@@ -71,6 +71,17 @@ NTSTATUS HID_CreateDevice(DEVICE_OBJECT *native_device, HID_MINIDRIVER_REGISTRAT
     return STATUS_SUCCESS;
 }
 
+/* user32 reserves 1 & 2 for winemouse and winekeyboard,
+ * keep this in sync with user_private.h */
+#define WINE_MOUSE_HANDLE 1
+#define WINE_KEYBOARD_HANDLE 2
+
+static UINT32 alloc_rawinput_handle(void)
+{
+    static LONG counter = WINE_KEYBOARD_HANDLE + 1;
+    return InterlockedIncrement(&counter);
+}
+
 NTSTATUS HID_LinkDevice(DEVICE_OBJECT *device)
 {
     WCHAR device_instance_id[MAX_DEVICE_ID_LEN];
@@ -125,7 +136,13 @@ NTSTATUS HID_LinkDevice(DEVICE_OBJECT *device)
     {
         if (!IoRegisterDeviceInterface(device, &GUID_DEVINTERFACE_MOUSE, NULL, &ext->mouse_link_name))
             ext->is_mouse = TRUE;
+        ext->rawinput_handle = WINE_MOUSE_HANDLE;
     }
+    else if (ext->preparseData->caps.UsagePage == HID_USAGE_PAGE_GENERIC
+            && ext->preparseData->caps.Usage == HID_USAGE_GENERIC_KEYBOARD)
+        ext->rawinput_handle = WINE_KEYBOARD_HANDLE;
+    else
+        ext->rawinput_handle = alloc_rawinput_handle();
 
     return STATUS_SUCCESS;
 
diff --git a/dlls/hidclass.sys/hid.h b/dlls/hidclass.sys/hid.h
index 889b8c625c0..41f3766a535 100644
--- a/dlls/hidclass.sys/hid.h
+++ b/dlls/hidclass.sys/hid.h
@@ -51,6 +51,7 @@ typedef struct _BASE_DEVICE_EXTENSION {
     struct ReportRingBuffer *ring_buffer;
     HANDLE halt_event;
     HANDLE thread;
+    UINT32 rawinput_handle;
 
     KSPIN_LOCK irp_queue_lock;
     LIST_ENTRY irp_queue;
-- 
2.31.0




More information about the wine-devel mailing list