From dd998ca86ac47869e2ff577b63b961e470a88c9b Mon Sep 17 00:00:00 2001 From: Simon Rozman Date: Mon, 4 Feb 2019 11:52:42 +0100 Subject: Add support for setupapi.SetupDiCreateDeviceInfo() Signed-off-by: Simon Rozman --- setupapi/setupapi_windows.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'setupapi/setupapi_windows.go') diff --git a/setupapi/setupapi_windows.go b/setupapi/setupapi_windows.go index c08a37a..c1650db 100644 --- a/setupapi/setupapi_windows.go +++ b/setupapi/setupapi_windows.go @@ -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 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 @@ -85,6 +86,27 @@ func SetupDiClassGuidsFromNameEx(ClassName string, MachineName string) (ClassGui return } +// 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) + if err != nil { + return + } + + var deviceDescriptionUTF16 *uint16 + if DeviceDescription != "" { + deviceDescriptionUTF16, err = syscall.UTF16PtrFromString(DeviceDescription) + if err != nil { + return + } + } + + data := SP_DEVINFO_DATA{} + data.Size = uint32(unsafe.Sizeof(data)) + + 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 -- cgit v1.2.3