From: Aric Stewart Subject: [PATCH v5 2/2] hidclass.sys: use IoRegisterDeviceInterface Message-Id: <682e045c-a23d-ad77-824e-14d2e1836d1b@codeweavers.com> Date: Fri, 5 Oct 2018 08:09:39 -0500 Signed-off-by: Aric Stewart --- dlls/hidclass.sys/device.c | 60 ++++++++++++++++------------------------------ dlls/hidclass.sys/hid.h | 2 +- dlls/hidclass.sys/pnp.c | 4 +--- 3 files changed, 22 insertions(+), 44 deletions(-) diff --git a/dlls/hidclass.sys/device.c b/dlls/hidclass.sys/device.c index 3364eb328b..1591390376 100644 --- a/dlls/hidclass.sys/device.c +++ b/dlls/hidclass.sys/device.c @@ -42,12 +42,6 @@ WINE_DECLARE_DEBUG_CHANNEL(hid_report); static const WCHAR device_name_fmtW[] = {'\\','D','e','v','i','c','e', '\\','H','I','D','#','%','p','&','%','p',0}; -static const WCHAR device_link_fmtW[] = {'\\','?','?','\\','%','s','#','%','s',0}; -/* GUID_DEVINTERFACE_HID */ -static const WCHAR class_guid[] = {'{','4','D','1','E','5','5','B','2', - '-','F','1','6','F','-','1','1','C','F','-','8','8','C','B','-','0','0', - '1','1','1','1','0','0','0','0','3','0','}',0}; - NTSTATUS HID_CreateDevice(DEVICE_OBJECT *native_device, HID_MINIDRIVER_REGISTRATION *driver, DEVICE_OBJECT **device) { @@ -75,7 +69,7 @@ NTSTATUS HID_CreateDevice(DEVICE_OBJECT *native_device, HID_MINIDRIVER_REGISTRAT ext->deviceExtension.NextDeviceObject = native_device; ext->device_name = HeapAlloc(GetProcessHeap(), 0, (lstrlenW(dev_name) + 1) * sizeof(WCHAR)); lstrcpyW(ext->device_name, dev_name); - ext->link_name = NULL; + ext->link_name.Buffer = NULL; IoAttachDeviceToDeviceStack(*device, native_device); @@ -84,10 +78,8 @@ NTSTATUS HID_CreateDevice(DEVICE_OBJECT *native_device, HID_MINIDRIVER_REGISTRAT NTSTATUS HID_LinkDevice(DEVICE_OBJECT *device) { - WCHAR dev_link[255]; - WCHAR *ptr; SP_DEVINFO_DATA Data; - UNICODE_STRING nameW, linkW; + UNICODE_STRING nameW; NTSTATUS status; HDEVINFO devinfo; GUID hidGuid; @@ -96,25 +88,7 @@ NTSTATUS HID_LinkDevice(DEVICE_OBJECT *device) HidD_GetHidGuid(&hidGuid); ext = device->DeviceExtension; - sprintfW(dev_link, device_link_fmtW, ext->instance_id, class_guid); - ptr = dev_link + 4; - do { if (*ptr == '\\') *ptr = '#'; } while (*ptr++); - struprW(dev_link); - RtlInitUnicodeString( &nameW, ext->device_name); - RtlInitUnicodeString( &linkW, dev_link ); - - TRACE("Create link %s\n", debugstr_w(dev_link)); - - ext->link_name = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR) * (lstrlenW(dev_link) + 1)); - lstrcpyW(ext->link_name, dev_link); - - status = IoCreateSymbolicLink( &linkW, &nameW ); - if (status) - { - FIXME( "failed to create link error %x\n", status ); - return status; - } devinfo = SetupDiGetClassDevsW(&GUID_DEVCLASS_HIDCLASS, NULL, NULL, DIGCF_DEVICEINTERFACE); if (!devinfo) @@ -138,13 +112,22 @@ NTSTATUS HID_LinkDevice(DEVICE_OBJECT *device) FIXME( "failed to Register Device Info %x\n", GetLastError()); goto error; } - if (!SetupDiCreateDeviceInterfaceW( devinfo, &Data, &hidGuid, NULL, 0, NULL)) + SetupDiDestroyDeviceInfoList(devinfo); + + status = IoRegisterDeviceInterface(device, &hidGuid, NULL, &ext->link_name); + if (status != STATUS_SUCCESS) { - FIXME( "failed to Create Device Interface %x\n", GetLastError()); - goto error; + FIXME( "failed to register device interface %x\n", status ); + return status; + } + + status = IoCreateSymbolicLink( &ext->link_name, &nameW ); + if (status != STATUS_SUCCESS) + { + FIXME( "failed to create link error %x\n", status ); + return status; } - SetupDiDestroyDeviceInfoList(devinfo); return STATUS_SUCCESS; error: @@ -156,20 +139,17 @@ void HID_DeleteDevice(HID_MINIDRIVER_REGISTRATION *driver, DEVICE_OBJECT *device { NTSTATUS status; BASE_DEVICE_EXTENSION *ext; - UNICODE_STRING linkW; LIST_ENTRY *entry; IRP *irp; ext = device->DeviceExtension; - if (ext->link_name) + if (ext->link_name.Buffer) { - TRACE("Delete link %s\n", debugstr_w(ext->link_name)); - RtlInitUnicodeString(&linkW, ext->link_name); - - IoSetDeviceInterfaceState(&linkW, FALSE); + TRACE("Delete link %s\n", debugstr_w(ext->link_name.Buffer)); - status = IoDeleteSymbolicLink(&linkW); + IoSetDeviceInterfaceState(&ext->link_name, FALSE); + status = IoDeleteSymbolicLink(&ext->link_name); if (status != STATUS_SUCCESS) ERR("Delete Symbolic Link failed (%x)\n",status); } @@ -196,7 +176,7 @@ void HID_DeleteDevice(HID_MINIDRIVER_REGISTRATION *driver, DEVICE_OBJECT *device TRACE("Delete device(%p) %s\n", device, debugstr_w(ext->device_name)); HeapFree(GetProcessHeap(), 0, ext->device_name); - HeapFree(GetProcessHeap(), 0, ext->link_name); + RtlFreeUnicodeString(&ext->link_name); IoDeleteDevice(device); } diff --git a/dlls/hidclass.sys/hid.h b/dlls/hidclass.sys/hid.h index 4e8ba3ca2c..769b7155ee 100644 --- a/dlls/hidclass.sys/hid.h +++ b/dlls/hidclass.sys/hid.h @@ -47,7 +47,7 @@ typedef struct _BASE_DEVICE_EXTENSION { ULONG poll_interval; WCHAR *device_name; - WCHAR *link_name; + UNICODE_STRING link_name; WCHAR device_id[MAX_DEVICE_ID_LEN]; WCHAR instance_id[MAX_DEVICE_ID_LEN]; struct ReportRingBuffer *ring_buffer; diff --git a/dlls/hidclass.sys/pnp.c b/dlls/hidclass.sys/pnp.c index 34bd944629..47bd443a86 100644 --- a/dlls/hidclass.sys/pnp.c +++ b/dlls/hidclass.sys/pnp.c @@ -286,12 +286,10 @@ NTSTATUS WINAPI HID_PNP_Dispatch(DEVICE_OBJECT *device, IRP *irp) case IRP_MN_START_DEVICE: { BASE_DEVICE_EXTENSION *ext = device->DeviceExtension; - UNICODE_STRING linkU; rc = minidriver->PNPDispatch(device, irp); - RtlInitUnicodeString(&linkU, ext->link_name); - IoSetDeviceInterfaceState(&linkU, TRUE); + IoSetDeviceInterfaceState(&ext->link_name, TRUE); return rc; } case IRP_MN_REMOVE_DEVICE: