aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rozman <simon@rozman.si>2019-02-04 15:21:19 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2019-02-05 12:59:42 +0100
commitc15cbefc1283ce630d35573856fed2bf71eb0292 (patch)
treefa1b6181aee92f78a6537ac10269484f5c84b6d5
parentAdd support for setupapi.SetupDiCreateDeviceInfo() (diff)
downloadwireguard-go-c15cbefc1283ce630d35573856fed2bf71eb0292.tar.xz
wireguard-go-c15cbefc1283ce630d35573856fed2bf71eb0292.zip
Reorder data-types and functions to match SetupAPI.h
Adding functions with non-consistent order made setupapi package a mess. While we could reorder data-types and functions by alphabet - it would make searching easier - it would put ...Get... and ...Set... functions quite apart. Therefore, the SetupAPI.h order was adopted. Signed-off-by: Simon Rozman <simon@rozman.si>
-rw-r--r--setupapi/setupapi_windows.go193
-rw-r--r--setupapi/setupapi_windows_test.go192
-rw-r--r--setupapi/types_windows.go218
-rw-r--r--setupapi/zsetupapi_windows.go80
4 files changed, 349 insertions, 334 deletions
diff --git a/setupapi/setupapi_windows.go b/setupapi/setupapi_windows.go
index c1650db..a48042f 100644
--- a/setupapi/setupapi_windows.go
+++ b/setupapi/setupapi_windows.go
@@ -13,25 +13,10 @@ import (
"golang.org/x/sys/windows/registry"
)
-//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 setupDiCreateDeviceInfo(DeviceInfoSet DevInfo, DeviceName *uint16, ClassGUID *windows.GUID, DeviceDescription *uint16, hwndParent uintptr, CreationFlags DICD, DeviceInfoData *SP_DEVINFO_DATA) (err error) = setupapi.SetupDiCreateDeviceInfoW
//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
-//sys setupDiEnumDeviceInfo(DeviceInfoSet DevInfo, MemberIndex uint32, DeviceInfoData *SP_DEVINFO_DATA) (err error) = setupapi.SetupDiEnumDeviceInfo
-//sys setupDiOpenDevRegKey(DeviceInfoSet DevInfo, DeviceInfoData *SP_DEVINFO_DATA, Scope DICS_FLAG, HwProfile uint32, KeyType DIREG, samDesired uint32) (key windows.Handle, err error) [failretval==windows.InvalidHandle] = setupapi.SetupDiOpenDevRegKey
-//sys setupDiGetDeviceInstallParams(DeviceInfoSet DevInfo, DeviceInfoData *SP_DEVINFO_DATA, DeviceInstallParams *_SP_DEVINSTALL_PARAMS) (err error) = setupapi.SetupDiGetDeviceInstallParamsW
-//sys setupDiSetDeviceInstallParams(DeviceInfoSet DevInfo, DeviceInfoData *SP_DEVINFO_DATA, DeviceInstallParams *_SP_DEVINSTALL_PARAMS) (err error) = setupapi.SetupDiSetDeviceInstallParamsW
-//sys SetupDiGetClassInstallParams(DeviceInfoSet DevInfo, DeviceInfoData *SP_DEVINFO_DATA, ClassInstallParams *SP_CLASSINSTALL_HEADER, ClassInstallParamsSize uint32, RequiredSize *uint32) (err error) = setupapi.SetupDiGetClassInstallParamsW
-//sys SetupDiSetClassInstallParams(DeviceInfoSet DevInfo, DeviceInfoData *SP_DEVINFO_DATA, ClassInstallParams *SP_CLASSINSTALL_HEADER, ClassInstallParamsSize uint32) (err error) = setupapi.SetupDiSetClassInstallParamsW
-//sys SetupDiCallClassInstaller(InstallFunction DI_FUNCTION, DeviceInfoSet DevInfo, DeviceInfoData *SP_DEVINFO_DATA) (err error) = setupapi.SetupDiCallClassInstaller
-
-// SetupDiClassNameFromGuidEx function retrieves the class name associated with a class GUID. The class can be installed on a local or remote computer.
-func SetupDiClassNameFromGuidEx(ClassGUID *windows.GUID, MachineName string) (ClassName string, err error) {
- var classNameUTF16 [MAX_CLASS_NAME_LEN]uint16
+// 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)
@@ -39,53 +24,30 @@ func SetupDiClassNameFromGuidEx(ClassGUID *windows.GUID, MachineName string) (Cl
return
}
}
+ return setupDiCreateDeviceInfoListEx(ClassGUID, hwndParent, machineNameUTF16, 0)
+}
- err = setupDiClassNameFromGuidEx(ClassGUID, &classNameUTF16[0], MAX_CLASS_NAME_LEN, nil, machineNameUTF16, 0)
- if err != nil {
- return
- }
+//sys setupDiGetDeviceInfoListDetail(DeviceInfoSet DevInfo, DeviceInfoSetDetailData *_SP_DEVINFO_LIST_DETAIL_DATA) (err error) = setupapi.SetupDiGetDeviceInfoListDetailW
- ClassName = windows.UTF16ToString(classNameUTF16[:])
- return
-}
+// SetupDiGetDeviceInfoListDetail function retrieves information associated with a device information set including the class GUID, remote computer handle, and remote computer name.
+func SetupDiGetDeviceInfoListDetail(DeviceInfoSet DevInfo) (DeviceInfoSetDetailData *DevInfoListDetailData, err error) {
+ var _data _SP_DEVINFO_LIST_DETAIL_DATA
+ _data.Size = uint32(unsafe.Sizeof(_data))
-// SetupDiClassGuidsFromNameEx function retrieves the GUIDs associated with the specified class name. This resulting list contains the classes currently installed on a local or remote computer.
-func SetupDiClassGuidsFromNameEx(ClassName string, MachineName string) (ClassGuidList []windows.GUID, err error) {
- classNameUTF16, err := syscall.UTF16PtrFromString(ClassName)
+ err = setupDiGetDeviceInfoListDetail(DeviceInfoSet, &_data)
if err != nil {
return
}
- const bufLen = 4
- var buf [bufLen]windows.GUID
- var bufCount uint32
-
- var machineNameUTF16 *uint16
- if MachineName != "" {
- machineNameUTF16, err = syscall.UTF16PtrFromString(MachineName)
- if err != nil {
- return
- }
- }
-
- err = setupDiClassGuidsFromNameEx(classNameUTF16, &buf[0], bufLen, &bufCount, machineNameUTF16, 0)
- if err == nil {
- // The GUID array was sufficiently big. Return its slice.
- return buf[:bufCount], nil
- }
-
- if errWin, ok := err.(syscall.Errno); ok && errWin == windows.ERROR_INSUFFICIENT_BUFFER {
- // The GUID array was too small. Now that we got the required size, create another one big enough and retry.
- buf := make([]windows.GUID, bufCount)
- err = setupDiClassGuidsFromNameEx(classNameUTF16, &buf[0], bufCount, &bufCount, machineNameUTF16, 0)
- if err == nil {
- return buf[:bufCount], nil
- }
- }
-
- return
+ return &DevInfoListDetailData{
+ ClassGUID: _data.ClassGUID,
+ RemoteMachineHandle: _data.RemoteMachineHandle,
+ RemoteMachineName: windows.UTF16ToString(_data.RemoteMachineName[:]),
+ }, nil
}
+//sys setupDiCreateDeviceInfo(DeviceInfoSet DevInfo, DeviceName *uint16, ClassGUID *windows.GUID, DeviceDescription *uint16, hwndParent uintptr, CreationFlags DICD, DeviceInfoData *SP_DEVINFO_DATA) (err error) = setupapi.SetupDiCreateDeviceInfoW
+
// SetupDiCreateDeviceInfo function creates a new device information element and adds it as a new member to the specified device information set.
func SetupDiCreateDeviceInfo(DeviceInfoSet DevInfo, DeviceName string, ClassGUID *windows.GUID, DeviceDescription string, hwndParent uintptr, CreationFlags DICD) (DeviceInfoData *SP_DEVINFO_DATA, err error) {
deviceNameUTF16, err := syscall.UTF16PtrFromString(DeviceName)
@@ -107,18 +69,21 @@ func SetupDiCreateDeviceInfo(DeviceInfoSet DevInfo, DeviceName string, ClassGUID
return &data, setupDiCreateDeviceInfo(DeviceInfoSet, deviceNameUTF16, ClassGUID, deviceDescriptionUTF16, hwndParent, CreationFlags, &data)
}
-// 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)
+//sys setupDiEnumDeviceInfo(DeviceInfoSet DevInfo, MemberIndex uint32, DeviceInfoData *SP_DEVINFO_DATA) (err error) = setupapi.SetupDiEnumDeviceInfo
+
+// SetupDiEnumDeviceInfo function returns a SP_DEVINFO_DATA structure that specifies a device information element in a device information set.
+func SetupDiEnumDeviceInfo(DeviceInfoSet DevInfo, MemberIndex int) (DeviceInfoData *SP_DEVINFO_DATA, err error) {
+ data := SP_DEVINFO_DATA{}
+ data.Size = uint32(unsafe.Sizeof(data))
+
+ return &data, setupDiEnumDeviceInfo(DeviceInfoSet, uint32(MemberIndex), &data)
}
+// SetupDiDestroyDeviceInfoList function deletes a device information set and frees all associated memory.
+//sys SetupDiDestroyDeviceInfoList(DeviceInfoSet DevInfo) (err error) = setupapi.SetupDiDestroyDeviceInfoList
+
+//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
+
// 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
@@ -138,30 +103,10 @@ func SetupDiGetClassDevsEx(ClassGUID *windows.GUID, Enumerator string, hwndParen
return setupDiGetClassDevsEx(ClassGUID, enumeratorUTF16, hwndParent, Flags, DeviceInfoSet, machineNameUTF16, 0)
}
-// SetupDiGetDeviceInfoListDetail function retrieves information associated with a device information set including the class GUID, remote computer handle, and remote computer name.
-func SetupDiGetDeviceInfoListDetail(DeviceInfoSet DevInfo) (DeviceInfoSetDetailData *DevInfoListDetailData, err error) {
- var _data _SP_DEVINFO_LIST_DETAIL_DATA
- _data.Size = uint32(unsafe.Sizeof(_data))
-
- err = setupDiGetDeviceInfoListDetail(DeviceInfoSet, &_data)
- if err != nil {
- return
- }
-
- return &DevInfoListDetailData{
- ClassGUID: _data.ClassGUID,
- RemoteMachineHandle: _data.RemoteMachineHandle,
- RemoteMachineName: windows.UTF16ToString(_data.RemoteMachineName[:]),
- }, nil
-}
-
-// SetupDiEnumDeviceInfo function returns a SP_DEVINFO_DATA structure that specifies a device information element in a device information set.
-func SetupDiEnumDeviceInfo(DeviceInfoSet DevInfo, MemberIndex int) (DeviceInfoData *SP_DEVINFO_DATA, err error) {
- data := SP_DEVINFO_DATA{}
- data.Size = uint32(unsafe.Sizeof(data))
+// SetupDiCallClassInstaller function calls the appropriate class installer, and any registered co-installers, with the specified installation request (DIF code).
+//sys SetupDiCallClassInstaller(InstallFunction DI_FUNCTION, DeviceInfoSet DevInfo, DeviceInfoData *SP_DEVINFO_DATA) (err error) = setupapi.SetupDiCallClassInstaller
- return &data, setupDiEnumDeviceInfo(DeviceInfoSet, uint32(MemberIndex), &data)
-}
+//sys setupDiOpenDevRegKey(DeviceInfoSet DevInfo, DeviceInfoData *SP_DEVINFO_DATA, Scope DICS_FLAG, HwProfile uint32, KeyType DIREG, samDesired uint32) (key windows.Handle, err error) [failretval==windows.InvalidHandle] = setupapi.SetupDiOpenDevRegKey
// SetupDiOpenDevRegKey function opens a registry key for device-specific configuration information.
func SetupDiOpenDevRegKey(DeviceInfoSet DevInfo, DeviceInfoData *SP_DEVINFO_DATA, Scope DICS_FLAG, HwProfile uint32, KeyType DIREG, samDesired uint32) (key registry.Key, err error) {
@@ -169,6 +114,8 @@ func SetupDiOpenDevRegKey(DeviceInfoSet DevInfo, DeviceInfoData *SP_DEVINFO_DATA
return registry.Key(handle), err
}
+//sys setupDiGetDeviceInstallParams(DeviceInfoSet DevInfo, DeviceInfoData *SP_DEVINFO_DATA, DeviceInstallParams *_SP_DEVINSTALL_PARAMS) (err error) = setupapi.SetupDiGetDeviceInstallParamsW
+
// SetupDiGetDeviceInstallParams function retrieves device installation parameters for a device information set or a particular device information element.
func SetupDiGetDeviceInstallParams(DeviceInfoSet DevInfo, DeviceInfoData *SP_DEVINFO_DATA) (DeviceInstallParams *DevInstallParams, err error) {
var _data _SP_DEVINSTALL_PARAMS
@@ -190,6 +137,11 @@ func SetupDiGetDeviceInstallParams(DeviceInfoSet DevInfo, DeviceInfoData *SP_DEV
}, nil
}
+// SetupDiGetClassInstallParams function retrieves class installation parameters for a device information set or a particular device information element.
+//sys SetupDiGetClassInstallParams(DeviceInfoSet DevInfo, DeviceInfoData *SP_DEVINFO_DATA, ClassInstallParams *SP_CLASSINSTALL_HEADER, ClassInstallParamsSize uint32, RequiredSize *uint32) (err error) = setupapi.SetupDiGetClassInstallParamsW
+
+//sys setupDiSetDeviceInstallParams(DeviceInfoSet DevInfo, DeviceInfoData *SP_DEVINFO_DATA, DeviceInstallParams *_SP_DEVINSTALL_PARAMS) (err error) = setupapi.SetupDiSetDeviceInstallParamsW
+
// SetupDiSetDeviceInstallParams function sets device installation parameters for a device information set or a particular device information element.
func SetupDiSetDeviceInstallParams(DeviceInfoSet DevInfo, DeviceInfoData *SP_DEVINFO_DATA, DeviceInstallParams *DevInstallParams) (err error) {
_data := _SP_DEVINSTALL_PARAMS{
@@ -210,3 +162,68 @@ func SetupDiSetDeviceInstallParams(DeviceInfoSet DevInfo, DeviceInfoData *SP_DEV
return setupDiSetDeviceInstallParams(DeviceInfoSet, DeviceInfoData, &_data)
}
+
+// SetupDiSetClassInstallParams function sets or clears class install parameters for a device information set or a particular device information element.
+//sys SetupDiSetClassInstallParams(DeviceInfoSet DevInfo, DeviceInfoData *SP_DEVINFO_DATA, ClassInstallParams *SP_CLASSINSTALL_HEADER, ClassInstallParamsSize uint32) (err error) = setupapi.SetupDiSetClassInstallParamsW
+
+//sys setupDiClassNameFromGuidEx(ClassGUID *windows.GUID, ClassName *uint16, ClassNameSize uint32, RequiredSize *uint32, MachineName *uint16, Reserved uintptr) (err error) = setupapi.SetupDiClassNameFromGuidExW
+
+// SetupDiClassNameFromGuidEx function retrieves the class name associated with a class GUID. The class can be installed on a local or remote computer.
+func SetupDiClassNameFromGuidEx(ClassGUID *windows.GUID, MachineName string) (ClassName string, err error) {
+ var classNameUTF16 [MAX_CLASS_NAME_LEN]uint16
+
+ var machineNameUTF16 *uint16
+ if MachineName != "" {
+ machineNameUTF16, err = syscall.UTF16PtrFromString(MachineName)
+ if err != nil {
+ return
+ }
+ }
+
+ err = setupDiClassNameFromGuidEx(ClassGUID, &classNameUTF16[0], MAX_CLASS_NAME_LEN, nil, machineNameUTF16, 0)
+ if err != nil {
+ return
+ }
+
+ ClassName = windows.UTF16ToString(classNameUTF16[:])
+ return
+}
+
+//sys setupDiClassGuidsFromNameEx(ClassName *uint16, ClassGuidList *windows.GUID, ClassGuidListSize uint32, RequiredSize *uint32, MachineName *uint16, Reserved uintptr) (err error) = setupapi.SetupDiClassGuidsFromNameExW
+
+// SetupDiClassGuidsFromNameEx function retrieves the GUIDs associated with the specified class name. This resulting list contains the classes currently installed on a local or remote computer.
+func SetupDiClassGuidsFromNameEx(ClassName string, MachineName string) (ClassGuidList []windows.GUID, err error) {
+ classNameUTF16, err := syscall.UTF16PtrFromString(ClassName)
+ if err != nil {
+ return
+ }
+
+ const bufLen = 4
+ var buf [bufLen]windows.GUID
+ var bufCount uint32
+
+ var machineNameUTF16 *uint16
+ if MachineName != "" {
+ machineNameUTF16, err = syscall.UTF16PtrFromString(MachineName)
+ if err != nil {
+ return
+ }
+ }
+
+ err = setupDiClassGuidsFromNameEx(classNameUTF16, &buf[0], bufLen, &bufCount, machineNameUTF16, 0)
+ if err == nil {
+ // The GUID array was sufficiently big. Return its slice.
+ return buf[:bufCount], nil
+ }
+
+ if errWin, ok := err.(syscall.Errno); ok && errWin == windows.ERROR_INSUFFICIENT_BUFFER {
+ // The GUID array was too small. Now that we got the required size, create another one big enough and retry.
+ buf := make([]windows.GUID, bufCount)
+ err = setupDiClassGuidsFromNameEx(classNameUTF16, &buf[0], bufCount, &bufCount, machineNameUTF16, 0)
+ if err == nil {
+ return buf[:bufCount], nil
+ }
+ }
+
+ return
+}
diff --git a/setupapi/setupapi_windows_test.go b/setupapi/setupapi_windows_test.go
index bfe82f6..4e07ed2 100644
--- a/setupapi/setupapi_windows_test.go
+++ b/setupapi/setupapi_windows_test.go
@@ -20,79 +20,6 @@ func init() {
computerName, _ = windows.ComputerName()
}
-func TestSetupDiClassNameFromGuidEx(t *testing.T) {
- deviceClassNetName, err := SetupDiClassNameFromGuidEx(&deviceClassNetGUID, "")
- if err != nil {
- t.Errorf("Error calling SetupDiClassNameFromGuidEx: %s", err.Error())
- } else if strings.ToLower(deviceClassNetName) != "net" {
- t.Errorf("SetupDiClassNameFromGuidEx(%x) should return \"Net\"", deviceClassNetGUID)
- }
-
- deviceClassNetName, err = SetupDiClassNameFromGuidEx(&deviceClassNetGUID, computerName)
- if err != nil {
- t.Errorf("Error calling SetupDiClassNameFromGuidEx: %s", err.Error())
- } else if strings.ToLower(deviceClassNetName) != "net" {
- t.Errorf("SetupDiClassNameFromGuidEx(%x) should return \"Net\"", deviceClassNetGUID)
- }
-
- _, err = SetupDiClassNameFromGuidEx(nil, "")
- if err == nil {
- t.Errorf("SetupDiClassNameFromGuidEx(nil) should fail")
- } else {
- if errWin, ok := err.(syscall.Errno); !ok || errWin != 1784 /*ERROR_INVALID_USER_BUFFER*/ {
- t.Errorf("SetupDiClassNameFromGuidEx(nil) should fail with ERROR_INVALID_USER_BUFFER")
- }
- }
-}
-
-func TestSetupDiClassGuidsFromNameEx(t *testing.T) {
- ClassGUIDs, err := SetupDiClassGuidsFromNameEx("Net", "")
- if err != nil {
- t.Errorf("Error calling SetupDiClassGuidsFromNameEx: %s", err.Error())
- } else {
- found := false
- for i := range ClassGUIDs {
- if ClassGUIDs[i] == deviceClassNetGUID {
- found = true
- break
- }
- }
- if !found {
- t.Errorf("SetupDiClassGuidsFromNameEx(\"Net\") should return %x", deviceClassNetGUID)
- }
- }
-
- ClassGUIDs, err = SetupDiClassGuidsFromNameEx("foobar-34274a51-a6e6-45f0-80d6-c62be96dd5fe", computerName)
- if err != nil {
- t.Errorf("Error calling SetupDiClassGuidsFromNameEx: %s", err.Error())
- } else if len(ClassGUIDs) != 0 {
- t.Errorf("SetupDiClassGuidsFromNameEx(\"foobar-34274a51-a6e6-45f0-80d6-c62be96dd5fe\") should return an empty GUID set")
- }
-}
-
-func TestSetupDiCreateDeviceInfo(t *testing.T) {
- devInfoList, err := SetupDiCreateDeviceInfoListEx(&deviceClassNetGUID, 0, computerName)
- if err != nil {
- t.Errorf("Error calling SetupDiCreateDeviceInfoListEx: %s", err.Error())
- }
- defer devInfoList.Close()
-
- deviceClassNetName, err := SetupDiClassNameFromGuidEx(&deviceClassNetGUID, computerName)
- if err != nil {
- t.Errorf("Error calling SetupDiClassNameFromGuidEx: %s", err.Error())
- }
-
- devInfoData, err := SetupDiCreateDeviceInfo(devInfoList, deviceClassNetName, &deviceClassNetGUID, "This is a test device", 0, DICD_GENERATE_ID)
- if err != nil {
- // Access denied is expected, as the SetupDiCreateDeviceInfo() require elevation to succeed.
- if errWin, ok := err.(syscall.Errno); !ok || errWin != windows.ERROR_ACCESS_DENIED {
- t.Errorf("Error calling SetupDiCreateDeviceInfo: %s", err.Error())
- }
- } else if devInfoData.ClassGUID != deviceClassNetGUID {
- t.Error("SetupDiCreateDeviceInfo returned different class GUID")
- }
-}
-
func TestSetupDiCreateDeviceInfoListEx(t *testing.T) {
devInfoList, err := SetupDiCreateDeviceInfoListEx(&deviceClassNetGUID, 0, "")
if err == nil {
@@ -116,26 +43,7 @@ func TestSetupDiCreateDeviceInfoListEx(t *testing.T) {
}
}
-func TestSetupDiGetClassDevsEx(t *testing.T) {
- devInfoList, err := SetupDiGetClassDevsEx(&deviceClassNetGUID, "PCI", 0, DIGCF_PRESENT, DevInfo(0), computerName)
- if err == nil {
- devInfoList.Close()
- } else {
- t.Errorf("Error calling SetupDiGetClassDevsEx: %s", err.Error())
- }
-
- devInfoList, err = SetupDiGetClassDevsEx(nil, "", 0, DIGCF_PRESENT, DevInfo(0), "")
- if err == nil {
- devInfoList.Close()
- t.Errorf("SetupDiGetClassDevsEx(nil, ...) should fail")
- } else {
- if errWin, ok := err.(syscall.Errno); !ok || errWin != 87 /*ERROR_INVALID_PARAMETER*/ {
- t.Errorf("SetupDiGetClassDevsEx(nil, ...) should fail with ERROR_INVALID_PARAMETER")
- }
- }
-}
-
-func TestSetupDiGetDeviceInfoListDetailLocal(t *testing.T) {
+func TestSetupDiGetDeviceInfoListDetail(t *testing.T) {
devInfoList, err := SetupDiGetClassDevsEx(&deviceClassNetGUID, "", 0, DIGCF_PRESENT, DevInfo(0), "")
if err != nil {
t.Errorf("Error calling SetupDiGetClassDevsEx: %s", err.Error())
@@ -158,16 +66,14 @@ func TestSetupDiGetDeviceInfoListDetailLocal(t *testing.T) {
t.Error("SetupDiGetDeviceInfoListDetail returned non-NULL remote machine name")
}
}
-}
-func TestSetupDiGetDeviceInfoListDetailRemote(t *testing.T) {
- devInfoList, err := SetupDiGetClassDevsEx(&deviceClassNetGUID, "", 0, DIGCF_PRESENT, DevInfo(0), computerName)
+ devInfoList, err = SetupDiGetClassDevsEx(&deviceClassNetGUID, "", 0, DIGCF_PRESENT, DevInfo(0), computerName)
if err != nil {
t.Errorf("Error calling SetupDiGetClassDevsEx: %s", err.Error())
}
defer devInfoList.Close()
- data, err := SetupDiGetDeviceInfoListDetail(devInfoList)
+ data, err = SetupDiGetDeviceInfoListDetail(devInfoList)
if err != nil {
t.Errorf("Error calling SetupDiGetDeviceInfoListDetail: %s", err.Error())
} else {
@@ -185,6 +91,29 @@ func TestSetupDiGetDeviceInfoListDetailRemote(t *testing.T) {
}
}
+func TestSetupDiCreateDeviceInfo(t *testing.T) {
+ devInfoList, err := SetupDiCreateDeviceInfoListEx(&deviceClassNetGUID, 0, computerName)
+ if err != nil {
+ t.Errorf("Error calling SetupDiCreateDeviceInfoListEx: %s", err.Error())
+ }
+ defer devInfoList.Close()
+
+ deviceClassNetName, err := SetupDiClassNameFromGuidEx(&deviceClassNetGUID, computerName)
+ if err != nil {
+ t.Errorf("Error calling SetupDiClassNameFromGuidEx: %s", err.Error())
+ }
+
+ devInfoData, err := SetupDiCreateDeviceInfo(devInfoList, deviceClassNetName, &deviceClassNetGUID, "This is a test device", 0, DICD_GENERATE_ID)
+ if err != nil {
+ // Access denied is expected, as the SetupDiCreateDeviceInfo() require elevation to succeed.
+ if errWin, ok := err.(syscall.Errno); !ok || errWin != windows.ERROR_ACCESS_DENIED {
+ t.Errorf("Error calling SetupDiCreateDeviceInfo: %s", err.Error())
+ }
+ } else if devInfoData.ClassGUID != deviceClassNetGUID {
+ t.Error("SetupDiCreateDeviceInfo returned different class GUID")
+ }
+}
+
func TestSetupDiEnumDeviceInfo(t *testing.T) {
devInfoList, err := SetupDiGetClassDevsEx(&deviceClassNetGUID, "", 0, DIGCF_PRESENT, DevInfo(0), "")
if err != nil {
@@ -207,6 +136,25 @@ func TestSetupDiEnumDeviceInfo(t *testing.T) {
}
}
+func TestSetupDiGetClassDevsEx(t *testing.T) {
+ devInfoList, err := SetupDiGetClassDevsEx(&deviceClassNetGUID, "PCI", 0, DIGCF_PRESENT, DevInfo(0), computerName)
+ if err == nil {
+ devInfoList.Close()
+ } else {
+ t.Errorf("Error calling SetupDiGetClassDevsEx: %s", err.Error())
+ }
+
+ devInfoList, err = SetupDiGetClassDevsEx(nil, "", 0, DIGCF_PRESENT, DevInfo(0), "")
+ if err == nil {
+ devInfoList.Close()
+ t.Errorf("SetupDiGetClassDevsEx(nil, ...) should fail")
+ } else {
+ if errWin, ok := err.(syscall.Errno); !ok || errWin != 87 /*ERROR_INVALID_PARAMETER*/ {
+ t.Errorf("SetupDiGetClassDevsEx(nil, ...) should fail with ERROR_INVALID_PARAMETER")
+ }
+ }
+}
+
func TestSetupDiOpenDevRegKey(t *testing.T) {
devInfoList, err := SetupDiGetClassDevsEx(&deviceClassNetGUID, "", 0, DIGCF_PRESENT, DevInfo(0), "")
if err != nil {
@@ -253,3 +201,53 @@ func TestSetupDiGetDeviceInstallParams(t *testing.T) {
}
}
}
+
+func TestSetupDiClassNameFromGuidEx(t *testing.T) {
+ deviceClassNetName, err := SetupDiClassNameFromGuidEx(&deviceClassNetGUID, "")
+ if err != nil {
+ t.Errorf("Error calling SetupDiClassNameFromGuidEx: %s", err.Error())
+ } else if strings.ToLower(deviceClassNetName) != "net" {
+ t.Errorf("SetupDiClassNameFromGuidEx(%x) should return \"Net\"", deviceClassNetGUID)
+ }
+
+ deviceClassNetName, err = SetupDiClassNameFromGuidEx(&deviceClassNetGUID, computerName)
+ if err != nil {
+ t.Errorf("Error calling SetupDiClassNameFromGuidEx: %s", err.Error())
+ } else if strings.ToLower(deviceClassNetName) != "net" {
+ t.Errorf("SetupDiClassNameFromGuidEx(%x) should return \"Net\"", deviceClassNetGUID)
+ }
+
+ _, err = SetupDiClassNameFromGuidEx(nil, "")
+ if err == nil {
+ t.Errorf("SetupDiClassNameFromGuidEx(nil) should fail")
+ } else {
+ if errWin, ok := err.(syscall.Errno); !ok || errWin != 1784 /*ERROR_INVALID_USER_BUFFER*/ {
+ t.Errorf("SetupDiClassNameFromGuidEx(nil) should fail with ERROR_INVALID_USER_BUFFER")
+ }
+ }
+}
+
+func TestSetupDiClassGuidsFromNameEx(t *testing.T) {
+ ClassGUIDs, err := SetupDiClassGuidsFromNameEx("Net", "")
+ if err != nil {
+ t.Errorf("Error calling SetupDiClassGuidsFromNameEx: %s", err.Error())
+ } else {
+ found := false
+ for i := range ClassGUIDs {
+ if ClassGUIDs[i] == deviceClassNetGUID {
+ found = true
+ break
+ }
+ }
+ if !found {
+ t.Errorf("SetupDiClassGuidsFromNameEx(\"Net\") should return %x", deviceClassNetGUID)
+ }
+ }
+
+ ClassGUIDs, err = SetupDiClassGuidsFromNameEx("foobar-34274a51-a6e6-45f0-80d6-c62be96dd5fe", computerName)
+ if err != nil {
+ t.Errorf("Error calling SetupDiClassGuidsFromNameEx: %s", err.Error())
+ } else if len(ClassGUIDs) != 0 {
+ t.Errorf("SetupDiClassGuidsFromNameEx(\"foobar-34274a51-a6e6-45f0-80d6-c62be96dd5fe\") should return an empty GUID set")
+ }
+}
diff --git a/setupapi/types_windows.go b/setupapi/types_windows.go
index 1ec910d..ef23614 100644
--- a/setupapi/types_windows.go
+++ b/setupapi/types_windows.go
@@ -20,24 +20,13 @@ const (
CONFIGMG_VERSION = 0x0400
)
-// DICD flags control SetupDiCreateDeviceInfo
-type DICD uint32
-
const (
- DICD_GENERATE_ID DICD = 0x00000001
- DICD_INHERIT_CLASSDRVS DICD = 0x00000002
+ // SP_MAX_MACHINENAME_LENGTH defines maximum length of a machine name in the format expected by ConfigMgr32 CM_Connect_Machine (i.e., "\\\\MachineName\0").
+ SP_MAX_MACHINENAME_LENGTH = windows.MAX_PATH + 3
)
-// DIGCF flags control what is included in the device information set built by SetupDiGetClassDevs
-type DIGCF uint32
-
-const (
- DIGCF_DEFAULT DIGCF = 0x00000001 // only valid with DIGCF_DEVICEINTERFACE
- DIGCF_PRESENT DIGCF = 0x00000002
- DIGCF_ALLCLASSES DIGCF = 0x00000004
- DIGCF_PROFILE DIGCF = 0x00000008
- DIGCF_DEVICEINTERFACE DIGCF = 0x00000010
-)
+// HSPFILEQ is type for setup file queue
+type HSPFILEQ uintptr
// DevInfo holds reference to device information set
type DevInfo windows.Handle
@@ -47,10 +36,13 @@ func (h DevInfo) Close() error {
return SetupDiDestroyDeviceInfoList(h)
}
-const (
- // SP_MAX_MACHINENAME_LENGTH defines maximum length of a machine name in the format expected by ConfigMgr32 CM_Connect_Machine (i.e., "\\\\MachineName\0").
- SP_MAX_MACHINENAME_LENGTH = windows.MAX_PATH + 3
-)
+// SP_DEVINFO_DATA is a device information structure (references a device instance that is a member of a device information set)
+type SP_DEVINFO_DATA struct {
+ Size uint32
+ ClassGUID windows.GUID
+ DevInst uint32 // DEVINST handle
+ _ uintptr
+}
type _SP_DEVINFO_LIST_DETAIL_DATA struct {
Size uint32
@@ -66,31 +58,74 @@ type DevInfoListDetailData struct {
RemoteMachineName string
}
-// SP_DEVINFO_DATA is a device information structure (references a device instance that is a member of a device information set)
-type SP_DEVINFO_DATA struct {
- Size uint32
- ClassGUID windows.GUID
- DevInst uint32 // DEVINST handle
- _ uintptr
-}
-
-// DICS_FLAG specifies the scope of a device property change
-type DICS_FLAG uint32
+// DI_FUNCTION is function type for device installer
+type DI_FUNCTION uint32
const (
- DICS_FLAG_GLOBAL DICS_FLAG = 0x00000001 // make change in all hardware profiles
- DICS_FLAG_CONFIGSPECIFIC DICS_FLAG = 0x00000002 // make change in specified profile only
- DICS_FLAG_CONFIGGENERAL DICS_FLAG = 0x00000004 // 1 or more hardware profile-specific changes to follow
+ DIF_SELECTDEVICE DI_FUNCTION = 0x00000001
+ DIF_INSTALLDEVICE DI_FUNCTION = 0x00000002
+ DIF_ASSIGNRESOURCES DI_FUNCTION = 0x00000003
+ DIF_PROPERTIES DI_FUNCTION = 0x00000004
+ DIF_REMOVE DI_FUNCTION = 0x00000005
+ DIF_FIRSTTIMESETUP DI_FUNCTION = 0x00000006
+ DIF_FOUNDDEVICE DI_FUNCTION = 0x00000007
+ DIF_SELECTCLASSDRIVERS DI_FUNCTION = 0x00000008
+ DIF_VALIDATECLASSDRIVERS DI_FUNCTION = 0x00000009
+ DIF_INSTALLCLASSDRIVERS DI_FUNCTION = 0x0000000A
+ DIF_CALCDISKSPACE DI_FUNCTION = 0x0000000B
+ DIF_DESTROYPRIVATEDATA DI_FUNCTION = 0x0000000C
+ DIF_VALIDATEDRIVER DI_FUNCTION = 0x0000000D
+ DIF_DETECT DI_FUNCTION = 0x0000000F
+ DIF_INSTALLWIZARD DI_FUNCTION = 0x00000010
+ DIF_DESTROYWIZARDDATA DI_FUNCTION = 0x00000011
+ DIF_PROPERTYCHANGE DI_FUNCTION = 0x00000012
+ DIF_ENABLECLASS DI_FUNCTION = 0x00000013
+ DIF_DETECTVERIFY DI_FUNCTION = 0x00000014
+ DIF_INSTALLDEVICEFILES DI_FUNCTION = 0x00000015
+ DIF_UNREMOVE DI_FUNCTION = 0x00000016
+ DIF_SELECTBESTCOMPATDRV DI_FUNCTION = 0x00000017
+ DIF_ALLOW_INSTALL DI_FUNCTION = 0x00000018
+ DIF_REGISTERDEVICE DI_FUNCTION = 0x00000019
+ DIF_NEWDEVICEWIZARD_PRESELECT DI_FUNCTION = 0x0000001A
+ DIF_NEWDEVICEWIZARD_SELECT DI_FUNCTION = 0x0000001B
+ DIF_NEWDEVICEWIZARD_PREANALYZE DI_FUNCTION = 0x0000001C
+ DIF_NEWDEVICEWIZARD_POSTANALYZE DI_FUNCTION = 0x0000001D
+ DIF_NEWDEVICEWIZARD_FINISHINSTALL DI_FUNCTION = 0x0000001E
+ DIF_INSTALLINTERFACES DI_FUNCTION = 0x00000020
+ DIF_DETECTCANCEL DI_FUNCTION = 0x00000021
+ DIF_REGISTER_COINSTALLERS DI_FUNCTION = 0x00000022
+ DIF_ADDPROPERTYPAGE_ADVANCED DI_FUNCTION = 0x00000023
+ DIF_ADDPROPERTYPAGE_BASIC DI_FUNCTION = 0x00000024
+ DIF_TROUBLESHOOTER DI_FUNCTION = 0x00000026
+ DIF_POWERMESSAGEWAKE DI_FUNCTION = 0x00000027
+ DIF_ADDREMOTEPROPERTYPAGE_ADVANCED DI_FUNCTION = 0x00000028
+ DIF_UPDATEDRIVER_UI DI_FUNCTION = 0x00000029
+ DIF_FINISHINSTALL_ACTION DI_FUNCTION = 0x0000002A
)
-// DIREG specifies values for SetupDiCreateDevRegKey, SetupDiOpenDevRegKey, and SetupDiDeleteDevRegKey.
-type DIREG uint32
+type _SP_DEVINSTALL_PARAMS struct {
+ Size uint32
+ Flags DI_FLAGS
+ FlagsEx DI_FLAGSEX
+ hwndParent uintptr
+ InstallMsgHandler uintptr
+ InstallMsgHandlerContext uintptr
+ FileQueue HSPFILEQ
+ _ uintptr
+ _ uint32
+ DriverPath [windows.MAX_PATH]uint16
+}
-const (
- DIREG_DEV DIREG = 0x00000001 // Open/Create/Delete device key
- DIREG_DRV DIREG = 0x00000002 // Open/Create/Delete driver key
- DIREG_BOTH DIREG = 0x00000004 // Delete both driver and Device key
-)
+// DevInstallParams is device installation parameters structure (associated with a particular device information element, or globally with a device information set)
+type DevInstallParams struct {
+ Flags DI_FLAGS
+ FlagsEx DI_FLAGSEX
+ hwndParent uintptr
+ InstallMsgHandler uintptr
+ InstallMsgHandlerContext uintptr
+ FileQueue HSPFILEQ
+ DriverPath string
+}
// DI_FLAGS is SP_DEVINSTALL_PARAMS.Flags values
type DI_FLAGS uint32
@@ -197,80 +232,45 @@ const (
DI_FLAGSEX_SEARCH_PUBLISHED_INFS DI_FLAGSEX = 0x80000000 // Tell SetupDiBuildDriverInfoList to do a "published INF" search
)
-// HSPFILEQ is type for setup file queue
-type HSPFILEQ uintptr
-
-type _SP_DEVINSTALL_PARAMS struct {
- Size uint32
- Flags DI_FLAGS
- FlagsEx DI_FLAGSEX
- hwndParent uintptr
- InstallMsgHandler uintptr
- InstallMsgHandlerContext uintptr
- FileQueue HSPFILEQ
- _ uintptr
- _ uint32
- DriverPath [windows.MAX_PATH]uint16
+// SP_CLASSINSTALL_HEADER is the first member of any class install parameters structure. It contains the device installation request code that defines the format of the rest of the install parameters structure.
+type SP_CLASSINSTALL_HEADER struct {
+ Size uint32
+ InstallFunction DI_FUNCTION
}
-// DevInstallParams is device installation parameters structure (associated with a particular device information element, or globally with a device information set)
-type DevInstallParams struct {
- Flags DI_FLAGS
- FlagsEx DI_FLAGSEX
- hwndParent uintptr
- InstallMsgHandler uintptr
- InstallMsgHandlerContext uintptr
- FileQueue HSPFILEQ
- DriverPath string
-}
+// DICS_FLAG specifies the scope of a device property change
+type DICS_FLAG uint32
-// DI_FUNCTION is function type for device installer
-type DI_FUNCTION uint32
+const (
+ DICS_FLAG_GLOBAL DICS_FLAG = 0x00000001 // make change in all hardware profiles
+ DICS_FLAG_CONFIGSPECIFIC DICS_FLAG = 0x00000002 // make change in specified profile only
+ DICS_FLAG_CONFIGGENERAL DICS_FLAG = 0x00000004 // 1 or more hardware profile-specific changes to follow
+)
+
+// DICD flags control SetupDiCreateDeviceInfo
+type DICD uint32
const (
- DIF_SELECTDEVICE DI_FUNCTION = 0x00000001
- DIF_INSTALLDEVICE DI_FUNCTION = 0x00000002
- DIF_ASSIGNRESOURCES DI_FUNCTION = 0x00000003
- DIF_PROPERTIES DI_FUNCTION = 0x00000004
- DIF_REMOVE DI_FUNCTION = 0x00000005
- DIF_FIRSTTIMESETUP DI_FUNCTION = 0x00000006
- DIF_FOUNDDEVICE DI_FUNCTION = 0x00000007
- DIF_SELECTCLASSDRIVERS DI_FUNCTION = 0x00000008
- DIF_VALIDATECLASSDRIVERS DI_FUNCTION = 0x00000009
- DIF_INSTALLCLASSDRIVERS DI_FUNCTION = 0x0000000A
- DIF_CALCDISKSPACE DI_FUNCTION = 0x0000000B
- DIF_DESTROYPRIVATEDATA DI_FUNCTION = 0x0000000C
- DIF_VALIDATEDRIVER DI_FUNCTION = 0x0000000D
- DIF_DETECT DI_FUNCTION = 0x0000000F
- DIF_INSTALLWIZARD DI_FUNCTION = 0x00000010
- DIF_DESTROYWIZARDDATA DI_FUNCTION = 0x00000011
- DIF_PROPERTYCHANGE DI_FUNCTION = 0x00000012
- DIF_ENABLECLASS DI_FUNCTION = 0x00000013
- DIF_DETECTVERIFY DI_FUNCTION = 0x00000014
- DIF_INSTALLDEVICEFILES DI_FUNCTION = 0x00000015
- DIF_UNREMOVE DI_FUNCTION = 0x00000016
- DIF_SELECTBESTCOMPATDRV DI_FUNCTION = 0x00000017
- DIF_ALLOW_INSTALL DI_FUNCTION = 0x00000018
- DIF_REGISTERDEVICE DI_FUNCTION = 0x00000019
- DIF_NEWDEVICEWIZARD_PRESELECT DI_FUNCTION = 0x0000001A
- DIF_NEWDEVICEWIZARD_SELECT DI_FUNCTION = 0x0000001B
- DIF_NEWDEVICEWIZARD_PREANALYZE DI_FUNCTION = 0x0000001C
- DIF_NEWDEVICEWIZARD_POSTANALYZE DI_FUNCTION = 0x0000001D
- DIF_NEWDEVICEWIZARD_FINISHINSTALL DI_FUNCTION = 0x0000001E
- DIF_INSTALLINTERFACES DI_FUNCTION = 0x00000020
- DIF_DETECTCANCEL DI_FUNCTION = 0x00000021
- DIF_REGISTER_COINSTALLERS DI_FUNCTION = 0x00000022
- DIF_ADDPROPERTYPAGE_ADVANCED DI_FUNCTION = 0x00000023
- DIF_ADDPROPERTYPAGE_BASIC DI_FUNCTION = 0x00000024
- DIF_TROUBLESHOOTER DI_FUNCTION = 0x00000026
- DIF_POWERMESSAGEWAKE DI_FUNCTION = 0x00000027
- DIF_ADDREMOTEPROPERTYPAGE_ADVANCED DI_FUNCTION = 0x00000028
- DIF_UPDATEDRIVER_UI DI_FUNCTION = 0x00000029
- DIF_FINISHINSTALL_ACTION DI_FUNCTION = 0x0000002A
+ DICD_GENERATE_ID DICD = 0x00000001
+ DICD_INHERIT_CLASSDRVS DICD = 0x00000002
)
-// SP_CLASSINSTALL_HEADER is the first member of any class install parameters structure. It contains the device installation request code that defines the format of the rest of the install parameters structure.
-type SP_CLASSINSTALL_HEADER struct {
- Size uint32
- InstallFunction DI_FUNCTION
-}
+// DIGCF flags control what is included in the device information set built by SetupDiGetClassDevs
+type DIGCF uint32
+
+const (
+ DIGCF_DEFAULT DIGCF = 0x00000001 // only valid with DIGCF_DEVICEINTERFACE
+ DIGCF_PRESENT DIGCF = 0x00000002
+ DIGCF_ALLCLASSES DIGCF = 0x00000004
+ DIGCF_PROFILE DIGCF = 0x00000008
+ DIGCF_DEVICEINTERFACE DIGCF = 0x00000010
+)
+
+// DIREG specifies values for SetupDiCreateDevRegKey, SetupDiOpenDevRegKey, and SetupDiDeleteDevRegKey.
+type DIREG uint32
+
+const (
+ DIREG_DEV DIREG = 0x00000001 // Open/Create/Delete device key
+ DIREG_DRV DIREG = 0x00000002 // Open/Create/Delete driver key
+ DIREG_BOTH DIREG = 0x00000004 // Delete both driver and Device key
+)
diff --git a/setupapi/zsetupapi_windows.go b/setupapi/zsetupapi_windows.go
index ae1b236..46a02c4 100644
--- a/setupapi/zsetupapi_windows.go
+++ b/setupapi/zsetupapi_windows.go
@@ -39,25 +39,26 @@ func errnoErr(e syscall.Errno) error {
var (
modsetupapi = windows.NewLazySystemDLL("setupapi.dll")
- procSetupDiClassNameFromGuidExW = modsetupapi.NewProc("SetupDiClassNameFromGuidExW")
- procSetupDiClassGuidsFromNameExW = modsetupapi.NewProc("SetupDiClassGuidsFromNameExW")
- procSetupDiCreateDeviceInfoW = modsetupapi.NewProc("SetupDiCreateDeviceInfoW")
procSetupDiCreateDeviceInfoListExW = modsetupapi.NewProc("SetupDiCreateDeviceInfoListExW")
- procSetupDiGetClassDevsExW = modsetupapi.NewProc("SetupDiGetClassDevsExW")
- procSetupDiDestroyDeviceInfoList = modsetupapi.NewProc("SetupDiDestroyDeviceInfoList")
procSetupDiGetDeviceInfoListDetailW = modsetupapi.NewProc("SetupDiGetDeviceInfoListDetailW")
+ procSetupDiCreateDeviceInfoW = modsetupapi.NewProc("SetupDiCreateDeviceInfoW")
procSetupDiEnumDeviceInfo = modsetupapi.NewProc("SetupDiEnumDeviceInfo")
+ procSetupDiDestroyDeviceInfoList = modsetupapi.NewProc("SetupDiDestroyDeviceInfoList")
+ procSetupDiGetClassDevsExW = modsetupapi.NewProc("SetupDiGetClassDevsExW")
+ procSetupDiCallClassInstaller = modsetupapi.NewProc("SetupDiCallClassInstaller")
procSetupDiOpenDevRegKey = modsetupapi.NewProc("SetupDiOpenDevRegKey")
procSetupDiGetDeviceInstallParamsW = modsetupapi.NewProc("SetupDiGetDeviceInstallParamsW")
- procSetupDiSetDeviceInstallParamsW = modsetupapi.NewProc("SetupDiSetDeviceInstallParamsW")
procSetupDiGetClassInstallParamsW = modsetupapi.NewProc("SetupDiGetClassInstallParamsW")
+ procSetupDiSetDeviceInstallParamsW = modsetupapi.NewProc("SetupDiSetDeviceInstallParamsW")
procSetupDiSetClassInstallParamsW = modsetupapi.NewProc("SetupDiSetClassInstallParamsW")
- procSetupDiCallClassInstaller = modsetupapi.NewProc("SetupDiCallClassInstaller")
+ procSetupDiClassNameFromGuidExW = modsetupapi.NewProc("SetupDiClassNameFromGuidExW")
+ procSetupDiClassGuidsFromNameExW = modsetupapi.NewProc("SetupDiClassGuidsFromNameExW")
)
-func setupDiClassNameFromGuidEx(ClassGUID *windows.GUID, ClassName *uint16, ClassNameSize uint32, RequiredSize *uint32, MachineName *uint16, Reserved uintptr) (err error) {
- r1, _, e1 := syscall.Syscall6(procSetupDiClassNameFromGuidExW.Addr(), 6, uintptr(unsafe.Pointer(ClassGUID)), uintptr(unsafe.Pointer(ClassName)), uintptr(ClassNameSize), uintptr(unsafe.Pointer(RequiredSize)), uintptr(unsafe.Pointer(MachineName)), uintptr(Reserved))
- if r1 == 0 {
+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 {
@@ -67,8 +68,8 @@ func setupDiClassNameFromGuidEx(ClassGUID *windows.GUID, ClassName *uint16, Clas
return
}
-func setupDiClassGuidsFromNameEx(ClassName *uint16, ClassGuidList *windows.GUID, ClassGuidListSize uint32, RequiredSize *uint32, MachineName *uint16, Reserved uintptr) (err error) {
- r1, _, e1 := syscall.Syscall6(procSetupDiClassGuidsFromNameExW.Addr(), 6, uintptr(unsafe.Pointer(ClassName)), uintptr(unsafe.Pointer(ClassGuidList)), uintptr(ClassGuidListSize), uintptr(unsafe.Pointer(RequiredSize)), uintptr(unsafe.Pointer(MachineName)), uintptr(Reserved))
+func setupDiGetDeviceInfoListDetail(DeviceInfoSet DevInfo, DeviceInfoSetDetailData *_SP_DEVINFO_LIST_DETAIL_DATA) (err error) {
+ r1, _, e1 := syscall.Syscall(procSetupDiGetDeviceInfoListDetailW.Addr(), 2, uintptr(DeviceInfoSet), uintptr(unsafe.Pointer(DeviceInfoSetDetailData)), 0)
if r1 == 0 {
if e1 != 0 {
err = errnoErr(e1)
@@ -91,23 +92,9 @@ func setupDiCreateDeviceInfo(DeviceInfoSet DevInfo, DeviceName *uint16, ClassGUI
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)
- if handle == DevInfo(windows.InvalidHandle) {
+func setupDiEnumDeviceInfo(DeviceInfoSet DevInfo, MemberIndex uint32, DeviceInfoData *SP_DEVINFO_DATA) (err error) {
+ r1, _, e1 := syscall.Syscall(procSetupDiEnumDeviceInfo.Addr(), 3, uintptr(DeviceInfoSet), uintptr(MemberIndex), uintptr(unsafe.Pointer(DeviceInfoData)))
+ if r1 == 0 {
if e1 != 0 {
err = errnoErr(e1)
} else {
@@ -129,9 +116,10 @@ func SetupDiDestroyDeviceInfoList(DeviceInfoSet DevInfo) (err error) {
return
}
-func setupDiGetDeviceInfoListDetail(DeviceInfoSet DevInfo, DeviceInfoSetDetailData *_SP_DEVINFO_LIST_DETAIL_DATA) (err error) {
- r1, _, e1 := syscall.Syscall(procSetupDiGetDeviceInfoListDetailW.Addr(), 2, uintptr(DeviceInfoSet), uintptr(unsafe.Pointer(DeviceInfoSetDetailData)), 0)
- if r1 == 0 {
+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)
+ if handle == DevInfo(windows.InvalidHandle) {
if e1 != 0 {
err = errnoErr(e1)
} else {
@@ -141,8 +129,8 @@ func setupDiGetDeviceInfoListDetail(DeviceInfoSet DevInfo, DeviceInfoSetDetailDa
return
}
-func setupDiEnumDeviceInfo(DeviceInfoSet DevInfo, MemberIndex uint32, DeviceInfoData *SP_DEVINFO_DATA) (err error) {
- r1, _, e1 := syscall.Syscall(procSetupDiEnumDeviceInfo.Addr(), 3, uintptr(DeviceInfoSet), uintptr(MemberIndex), uintptr(unsafe.Pointer(DeviceInfoData)))
+func SetupDiCallClassInstaller(InstallFunction DI_FUNCTION, DeviceInfoSet DevInfo, DeviceInfoData *SP_DEVINFO_DATA) (err error) {
+ r1, _, e1 := syscall.Syscall(procSetupDiCallClassInstaller.Addr(), 3, uintptr(InstallFunction), uintptr(DeviceInfoSet), uintptr(unsafe.Pointer(DeviceInfoData)))
if r1 == 0 {
if e1 != 0 {
err = errnoErr(e1)
@@ -178,8 +166,8 @@ func setupDiGetDeviceInstallParams(DeviceInfoSet DevInfo, DeviceInfoData *SP_DEV
return
}
-func setupDiSetDeviceInstallParams(DeviceInfoSet DevInfo, DeviceInfoData *SP_DEVINFO_DATA, DeviceInstallParams *_SP_DEVINSTALL_PARAMS) (err error) {
- r1, _, e1 := syscall.Syscall(procSetupDiSetDeviceInstallParamsW.Addr(), 3, uintptr(DeviceInfoSet), uintptr(unsafe.Pointer(DeviceInfoData)), uintptr(unsafe.Pointer(DeviceInstallParams)))
+func SetupDiGetClassInstallParams(DeviceInfoSet DevInfo, DeviceInfoData *SP_DEVINFO_DATA, ClassInstallParams *SP_CLASSINSTALL_HEADER, ClassInstallParamsSize uint32, RequiredSize *uint32) (err error) {
+ r1, _, e1 := syscall.Syscall6(procSetupDiGetClassInstallParamsW.Addr(), 5, uintptr(DeviceInfoSet), uintptr(unsafe.Pointer(DeviceInfoData)), uintptr(unsafe.Pointer(ClassInstallParams)), uintptr(ClassInstallParamsSize), uintptr(unsafe.Pointer(RequiredSize)), 0)
if r1 == 0 {
if e1 != 0 {
err = errnoErr(e1)
@@ -190,8 +178,8 @@ func setupDiSetDeviceInstallParams(DeviceInfoSet DevInfo, DeviceInfoData *SP_DEV
return
}
-func SetupDiGetClassInstallParams(DeviceInfoSet DevInfo, DeviceInfoData *SP_DEVINFO_DATA, ClassInstallParams *SP_CLASSINSTALL_HEADER, ClassInstallParamsSize uint32, RequiredSize *uint32) (err error) {
- r1, _, e1 := syscall.Syscall6(procSetupDiGetClassInstallParamsW.Addr(), 5, uintptr(DeviceInfoSet), uintptr(unsafe.Pointer(DeviceInfoData)), uintptr(unsafe.Pointer(ClassInstallParams)), uintptr(ClassInstallParamsSize), uintptr(unsafe.Pointer(RequiredSize)), 0)
+func setupDiSetDeviceInstallParams(DeviceInfoSet DevInfo, DeviceInfoData *SP_DEVINFO_DATA, DeviceInstallParams *_SP_DEVINSTALL_PARAMS) (err error) {
+ r1, _, e1 := syscall.Syscall(procSetupDiSetDeviceInstallParamsW.Addr(), 3, uintptr(DeviceInfoSet), uintptr(unsafe.Pointer(DeviceInfoData)), uintptr(unsafe.Pointer(DeviceInstallParams)))
if r1 == 0 {
if e1 != 0 {
err = errnoErr(e1)
@@ -214,8 +202,20 @@ func SetupDiSetClassInstallParams(DeviceInfoSet DevInfo, DeviceInfoData *SP_DEVI
return
}
-func SetupDiCallClassInstaller(InstallFunction DI_FUNCTION, DeviceInfoSet DevInfo, DeviceInfoData *SP_DEVINFO_DATA) (err error) {
- r1, _, e1 := syscall.Syscall(procSetupDiCallClassInstaller.Addr(), 3, uintptr(InstallFunction), uintptr(DeviceInfoSet), uintptr(unsafe.Pointer(DeviceInfoData)))
+func setupDiClassNameFromGuidEx(ClassGUID *windows.GUID, ClassName *uint16, ClassNameSize uint32, RequiredSize *uint32, MachineName *uint16, Reserved uintptr) (err error) {
+ r1, _, e1 := syscall.Syscall6(procSetupDiClassNameFromGuidExW.Addr(), 6, uintptr(unsafe.Pointer(ClassGUID)), uintptr(unsafe.Pointer(ClassName)), uintptr(ClassNameSize), uintptr(unsafe.Pointer(RequiredSize)), uintptr(unsafe.Pointer(MachineName)), uintptr(Reserved))
+ if r1 == 0 {
+ if e1 != 0 {
+ err = errnoErr(e1)
+ } else {
+ err = syscall.EINVAL
+ }
+ }
+ return
+}
+
+func setupDiClassGuidsFromNameEx(ClassName *uint16, ClassGuidList *windows.GUID, ClassGuidListSize uint32, RequiredSize *uint32, MachineName *uint16, Reserved uintptr) (err error) {
+ r1, _, e1 := syscall.Syscall6(procSetupDiClassGuidsFromNameExW.Addr(), 6, uintptr(unsafe.Pointer(ClassName)), uintptr(unsafe.Pointer(ClassGuidList)), uintptr(ClassGuidListSize), uintptr(unsafe.Pointer(RequiredSize)), uintptr(unsafe.Pointer(MachineName)), uintptr(Reserved))
if r1 == 0 {
if e1 != 0 {
err = errnoErr(e1)