setupapi: Merge _SP_DEVINFO_LIST_DETAIL_DATA and DevInfoListDetailData
Signed-off-by: Simon Rozman <simon@rozman.si>
This commit is contained in:
parent
6d2729dccc
commit
05d25fd1b7
@ -29,19 +29,14 @@ func SetupDiCreateDeviceInfoListEx(classGUID *windows.GUID, hwndParent uintptr,
|
||||
return setupDiCreateDeviceInfoListEx(classGUID, hwndParent, machineNameUTF16, 0)
|
||||
}
|
||||
|
||||
//sys setupDiGetDeviceInfoListDetail(deviceInfoSet DevInfo, deviceInfoSetDetailData *_SP_DEVINFO_LIST_DETAIL_DATA) (err error) = setupapi.SetupDiGetDeviceInfoListDetailW
|
||||
//sys setupDiGetDeviceInfoListDetail(deviceInfoSet DevInfo, deviceInfoSetDetailData *DevInfoListDetailData) (err error) = setupapi.SetupDiGetDeviceInfoListDetailW
|
||||
|
||||
// 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))
|
||||
data := &DevInfoListDetailData{}
|
||||
data.size = uint32(unsafe.Sizeof(*data))
|
||||
|
||||
err = setupDiGetDeviceInfoListDetail(deviceInfoSet, &_data)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return _data.toGo(), nil
|
||||
return data, setupDiGetDeviceInfoListDetail(deviceInfoSet, data)
|
||||
}
|
||||
|
||||
// GetDeviceInfoListDetail method retrieves information associated with a device information set including the class GUID, remote computer handle, and remote computer name.
|
||||
|
@ -63,7 +63,7 @@ func TestSetupDiGetDeviceInfoListDetail(t *testing.T) {
|
||||
t.Error("SetupDiGetDeviceInfoListDetail returned non-NULL remote machine handle")
|
||||
}
|
||||
|
||||
if data.RemoteMachineName != "" {
|
||||
if data.GetRemoteMachineName() != "" {
|
||||
t.Error("SetupDiGetDeviceInfoListDetail returned non-NULL remote machine name")
|
||||
}
|
||||
}
|
||||
@ -86,10 +86,16 @@ func TestSetupDiGetDeviceInfoListDetail(t *testing.T) {
|
||||
t.Error("SetupDiGetDeviceInfoListDetail returned NULL remote machine handle")
|
||||
}
|
||||
|
||||
if data.RemoteMachineName != computerName {
|
||||
if data.GetRemoteMachineName() != computerName {
|
||||
t.Error("SetupDiGetDeviceInfoListDetail returned different remote machine name")
|
||||
}
|
||||
}
|
||||
|
||||
data = &DevInfoListDetailData{}
|
||||
data.SetRemoteMachineName("foobar")
|
||||
if data.GetRemoteMachineName() != "foobar" {
|
||||
t.Error("DevInfoListDetailData.(Get|Set)RemoteMachineName() differ")
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetupDiCreateDeviceInfo(t *testing.T) {
|
||||
|
@ -57,26 +57,25 @@ type DevInfoData struct {
|
||||
_ uintptr
|
||||
}
|
||||
|
||||
type _SP_DEVINFO_LIST_DETAIL_DATA struct {
|
||||
Size uint32
|
||||
ClassGUID windows.GUID
|
||||
RemoteMachineHandle windows.Handle
|
||||
RemoteMachineName [SP_MAX_MACHINENAME_LENGTH]uint16
|
||||
}
|
||||
|
||||
func (_data *_SP_DEVINFO_LIST_DETAIL_DATA) toGo() *DevInfoListDetailData {
|
||||
return &DevInfoListDetailData{
|
||||
ClassGUID: _data.ClassGUID,
|
||||
RemoteMachineHandle: _data.RemoteMachineHandle,
|
||||
RemoteMachineName: windows.UTF16ToString(_data.RemoteMachineName[:]),
|
||||
}
|
||||
}
|
||||
|
||||
// DevInfoListDetailData is a structure for detailed information on a device information set (used for SetupDiGetDeviceInfoListDetail which supercedes the functionality of SetupDiGetDeviceInfoListClass).
|
||||
type DevInfoListDetailData struct {
|
||||
size uint32
|
||||
ClassGUID windows.GUID
|
||||
RemoteMachineHandle windows.Handle
|
||||
RemoteMachineName string
|
||||
remoteMachineName [SP_MAX_MACHINENAME_LENGTH]uint16
|
||||
}
|
||||
|
||||
func (data *DevInfoListDetailData) GetRemoteMachineName() string {
|
||||
return windows.UTF16ToString(data.remoteMachineName[:])
|
||||
}
|
||||
|
||||
func (data *DevInfoListDetailData) SetRemoteMachineName(remoteMachineName string) error {
|
||||
str, err := syscall.UTF16FromString(remoteMachineName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
copy(data.remoteMachineName[:], str)
|
||||
return nil
|
||||
}
|
||||
|
||||
// DI_FUNCTION is function type for device installer
|
||||
|
@ -79,7 +79,7 @@ func setupDiCreateDeviceInfoListEx(classGUID *windows.GUID, hwndParent uintptr,
|
||||
return
|
||||
}
|
||||
|
||||
func setupDiGetDeviceInfoListDetail(deviceInfoSet DevInfo, deviceInfoSetDetailData *_SP_DEVINFO_LIST_DETAIL_DATA) (err error) {
|
||||
func setupDiGetDeviceInfoListDetail(deviceInfoSet DevInfo, deviceInfoSetDetailData *DevInfoListDetailData) (err error) {
|
||||
r1, _, e1 := syscall.Syscall(procSetupDiGetDeviceInfoListDetailW.Addr(), 2, uintptr(deviceInfoSet), uintptr(unsafe.Pointer(deviceInfoSetDetailData)), 0)
|
||||
if r1 == 0 {
|
||||
if e1 != 0 {
|
||||
|
Loading…
Reference in New Issue
Block a user