[prev in list] [next in list] [prev in thread] [next in thread] 

List:       wine-devel
Subject:    [PATCH 7/8] =?UTF-8?q?setupapi:=20Re=C3=ABnumerate=20root=20PnP?= =?UTF-8?q?=20devices=20in=20SetupD
From:       Zebediah Figura <z.figura12 () gmail ! com>
Date:       2021-03-31 16:16:37
Message-ID: 20210331161638.1014645-7-z.figura12 () gmail ! com
[Download RAW message or body]

Allow them to be unloaded.

Signed-off-by: Zebediah Figura <z.figura12@gmail.com>
---
 dlls/setupapi/devinst.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/dlls/setupapi/devinst.c b/dlls/setupapi/devinst.c
index 0a396cc8464..8f826c30250 100644
--- a/dlls/setupapi/devinst.c
+++ b/dlls/setupapi/devinst.c
@@ -19,6 +19,7 @@
  */
 
 #include <stdarg.h>
+#include <stdlib.h>
 
 #include "windef.h"
 #include "winbase.h"
@@ -1692,15 +1693,38 @@ BOOL WINAPI SetupDiRegisterDeviceInfo(HDEVINFO devinfo, SP_DEVINFO_DATA *device_
  */
 BOOL WINAPI SetupDiRemoveDevice(HDEVINFO devinfo, SP_DEVINFO_DATA *device_data)
 {
+    SC_HANDLE manager = NULL, service = NULL;
     struct device *device;
+    WCHAR *service_name;
+    DWORD size;
 
     TRACE("devinfo %p, device_data %p.\n", devinfo, device_data);
 
     if (!(device = get_device(devinfo, device_data)))
         return FALSE;
 
+    if (!(manager = OpenSCManagerW(NULL, NULL, SC_MANAGER_CONNECT)))
+        return FALSE;
+
+    if (!RegGetValueW(device->key, NULL, L"Service", RRF_RT_REG_SZ, NULL, NULL, &size))
+    {
+        service_name = malloc(size);
+        if (!RegGetValueW(device->key, NULL, L"Service", RRF_RT_REG_SZ, NULL, service_name, &size))
+            service = OpenServiceW(manager, service_name, SERVICE_USER_DEFINED_CONTROL);
+        free(service_name);
+    }
+
     remove_device(device);
 
+    if (service)
+    {
+        SERVICE_STATUS status;
+        if (!ControlService(service, SERVICE_CONTROL_REENUMERATE_ROOT_DEVICES, &status))
+            ERR("Failed to control service %s, error %u.\n", debugstr_w(service_name), GetLastError());
+        CloseServiceHandle(service);
+    }
+    CloseServiceHandle(manager);
+
     return TRUE;
 }
 
-- 
2.30.2


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic