]> git.ipfire.org Git - thirdparty/wireguard-go.git/commitdiff
Add support for setupapi.setupDiCreateDeviceInfoListEx()
authorSimon Rozman <simon@rozman.si>
Mon, 4 Feb 2019 10:49:26 +0000 (11:49 +0100)
committerJason A. Donenfeld <Jason@zx2c4.com>
Tue, 5 Feb 2019 11:59:42 +0000 (12:59 +0100)
Signed-off-by: Simon Rozman <simon@rozman.si>
setupapi/setupapi_windows.go
setupapi/setupapi_windows_test.go
setupapi/zsetupapi_windows.go

index f6b35d2266deb2e721f988d8d82d5b369dc1a7f1..c08a37a510b588b8f6d381727ce7f1c5c008771b 100644 (file)
@@ -15,6 +15,7 @@ import (
 
 //sys  setupDiClassNameFromGuidEx(ClassGUID *windows.GUID, ClassName *uint16, ClassNameSize uint32, RequiredSize *uint32, MachineName *uint16, Reserved uintptr) (err error) = setupapi.SetupDiClassNameFromGuidExW
 //sys  setupDiClassGuidsFromNameEx(ClassName *uint16, ClassGuidList *windows.GUID, ClassGuidListSize uint32, RequiredSize *uint32, MachineName *uint16, Reserved uintptr) (err error) = setupapi.SetupDiClassGuidsFromNameExW
+//sys  setupDiCreateDeviceInfoListEx(ClassGUID *windows.GUID, hwndParent uintptr, MachineName *uint16, Reserved uintptr) (handle DevInfo, err error) [failretval==DevInfo(windows.InvalidHandle)] = setupapi.SetupDiCreateDeviceInfoListExW
 //sys  setupDiGetClassDevsEx(ClassGUID *windows.GUID, Enumerator *uint16, hwndParent uintptr, Flags DIGCF, DeviceInfoSet DevInfo, MachineName *uint16, reserved uintptr) (handle DevInfo, err error) [failretval==DevInfo(windows.InvalidHandle)] = setupapi.SetupDiGetClassDevsExW
 //sys  SetupDiDestroyDeviceInfoList(DeviceInfoSet DevInfo) (err error) = setupapi.SetupDiDestroyDeviceInfoList
 //sys  setupDiGetDeviceInfoListDetail(DeviceInfoSet DevInfo, DeviceInfoSetDetailData *_SP_DEVINFO_LIST_DETAIL_DATA) (err error) = setupapi.SetupDiGetDeviceInfoListDetailW
@@ -84,6 +85,18 @@ func SetupDiClassGuidsFromNameEx(ClassName string, MachineName string) (ClassGui
        return
 }
 
+// SetupDiCreateDeviceInfoListEx function creates an empty device information set on a remote or a local computer and optionally associates the set with a device setup class.
+func SetupDiCreateDeviceInfoListEx(ClassGUID *windows.GUID, hwndParent uintptr, MachineName string) (handle DevInfo, err error) {
+       var machineNameUTF16 *uint16
+       if MachineName != "" {
+               machineNameUTF16, err = syscall.UTF16PtrFromString(MachineName)
+               if err != nil {
+                       return
+               }
+       }
+       return setupDiCreateDeviceInfoListEx(ClassGUID, hwndParent, machineNameUTF16, 0)
+}
+
 // SetupDiGetClassDevsEx function returns a handle to a device information set that contains requested device information elements for a local or a remote computer.
 func SetupDiGetClassDevsEx(ClassGUID *windows.GUID, Enumerator string, hwndParent uintptr, Flags DIGCF, DeviceInfoSet DevInfo, MachineName string) (handle DevInfo, err error) {
        var enumeratorUTF16 *uint16
index 17d6d8e36ff04b427d3c64f741ef881b29d6f57b..c99da6f9c1908dd1e348ed4bf978498429f22660 100644 (file)
@@ -70,6 +70,29 @@ func TestSetupDiClassGuidsFromNameEx(t *testing.T) {
        }
 }
 
+func TestSetupDiCreateDeviceInfoListEx(t *testing.T) {
+       devInfoList, err := SetupDiCreateDeviceInfoListEx(&deviceClassNetGUID, 0, "")
+       if err == nil {
+               devInfoList.Close()
+       } else {
+               t.Errorf("Error calling SetupDiCreateDeviceInfoListEx: %s", err.Error())
+       }
+
+       devInfoList, err = SetupDiCreateDeviceInfoListEx(&deviceClassNetGUID, 0, computerName)
+       if err == nil {
+               devInfoList.Close()
+       } else {
+               t.Errorf("Error calling SetupDiCreateDeviceInfoListEx: %s", err.Error())
+       }
+
+       devInfoList, err = SetupDiCreateDeviceInfoListEx(nil, 0, "")
+       if err == nil {
+               devInfoList.Close()
+       } else {
+               t.Errorf("Error calling SetupDiCreateDeviceInfoListEx(nil): %s", err.Error())
+       }
+}
+
 func TestSetupDiGetClassDevsEx(t *testing.T) {
        devInfoList, err := SetupDiGetClassDevsEx(&deviceClassNetGUID, "PCI", 0, DIGCF_PRESENT, DevInfo(0), computerName)
        if err == nil {
index 324749fe74e2fdf9cc7f3bf2cc078e521beafb9b..a242bc8636161b74af8a6f04278903c58097ba46 100644 (file)
@@ -41,6 +41,7 @@ var (
 
        procSetupDiClassNameFromGuidExW     = modsetupapi.NewProc("SetupDiClassNameFromGuidExW")
        procSetupDiClassGuidsFromNameExW    = modsetupapi.NewProc("SetupDiClassGuidsFromNameExW")
+       procSetupDiCreateDeviceInfoListExW  = modsetupapi.NewProc("SetupDiCreateDeviceInfoListExW")
        procSetupDiGetClassDevsExW          = modsetupapi.NewProc("SetupDiGetClassDevsExW")
        procSetupDiDestroyDeviceInfoList    = modsetupapi.NewProc("SetupDiDestroyDeviceInfoList")
        procSetupDiGetDeviceInfoListDetailW = modsetupapi.NewProc("SetupDiGetDeviceInfoListDetailW")
@@ -77,6 +78,19 @@ func setupDiClassGuidsFromNameEx(ClassName *uint16, ClassGuidList *windows.GUID,
        return
 }
 
+func setupDiCreateDeviceInfoListEx(ClassGUID *windows.GUID, hwndParent uintptr, MachineName *uint16, Reserved uintptr) (handle DevInfo, err error) {
+       r0, _, e1 := syscall.Syscall6(procSetupDiCreateDeviceInfoListExW.Addr(), 4, uintptr(unsafe.Pointer(ClassGUID)), uintptr(hwndParent), uintptr(unsafe.Pointer(MachineName)), uintptr(Reserved), 0, 0)
+       handle = DevInfo(r0)
+       if handle == DevInfo(windows.InvalidHandle) {
+               if e1 != 0 {
+                       err = errnoErr(e1)
+               } else {
+                       err = syscall.EINVAL
+               }
+       }
+       return
+}
+
 func setupDiGetClassDevsEx(ClassGUID *windows.GUID, Enumerator *uint16, hwndParent uintptr, Flags DIGCF, DeviceInfoSet DevInfo, MachineName *uint16, reserved uintptr) (handle DevInfo, err error) {
        r0, _, e1 := syscall.Syscall9(procSetupDiGetClassDevsExW.Addr(), 7, uintptr(unsafe.Pointer(ClassGUID)), uintptr(unsafe.Pointer(Enumerator)), uintptr(hwndParent), uintptr(Flags), uintptr(DeviceInfoSet), uintptr(unsafe.Pointer(MachineName)), uintptr(reserved), 0, 0)
        handle = DevInfo(r0)