aboutsummaryrefslogtreecommitdiffstats
path: root/setupapi/types_windows.go
diff options
context:
space:
mode:
authorSimon Rozman <simon@rozman.si>2019-02-05 14:03:28 +0100
committerSimon Rozman <simon@rozman.si>2019-02-05 14:03:28 +0100
commit7b636380e50f257e7f1b98b6b5829a24166e2000 (patch)
tree3b0509d0548c8d911dc7d97b8af9b57e33f314c0 /setupapi/types_windows.go
parentsetupapi: Add support for SetupDi(Get|Set)DeviceRegistryProperty() (diff)
downloadwireguard-go-7b636380e50f257e7f1b98b6b5829a24166e2000.tar.xz
wireguard-go-7b636380e50f257e7f1b98b6b5829a24166e2000.zip
setupapi: Move Go<>Windows struct marshaling to types_windows.go
Signed-off-by: Simon Rozman <simon@rozman.si>
Diffstat (limited to 'setupapi/types_windows.go')
-rw-r--r--setupapi/types_windows.go43
1 files changed, 43 insertions, 0 deletions
diff --git a/setupapi/types_windows.go b/setupapi/types_windows.go
index c93d3aa..9bbe38b 100644
--- a/setupapi/types_windows.go
+++ b/setupapi/types_windows.go
@@ -6,6 +6,9 @@
package setupapi
import (
+ "syscall"
+ "unsafe"
+
"golang.org/x/sys/windows"
)
@@ -46,6 +49,14 @@ type _SP_DEVINFO_LIST_DETAIL_DATA struct {
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 {
ClassGUID windows.GUID
@@ -111,6 +122,18 @@ type _SP_DEVINSTALL_PARAMS struct {
DriverPath [windows.MAX_PATH]uint16
}
+func (_data _SP_DEVINSTALL_PARAMS) toGo() *DevInstallParams {
+ return &DevInstallParams{
+ Flags: _data.Flags,
+ FlagsEx: _data.FlagsEx,
+ hwndParent: _data.hwndParent,
+ InstallMsgHandler: _data.InstallMsgHandler,
+ InstallMsgHandlerContext: _data.InstallMsgHandlerContext,
+ FileQueue: _data.FileQueue,
+ DriverPath: windows.UTF16ToString(_data.DriverPath[:]),
+ }
+}
+
// 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
@@ -122,6 +145,26 @@ type DevInstallParams struct {
DriverPath string
}
+func (DeviceInstallParams DevInstallParams) toWindows() (_data *_SP_DEVINSTALL_PARAMS, err error) {
+ _data = &_SP_DEVINSTALL_PARAMS{
+ Flags: DeviceInstallParams.Flags,
+ FlagsEx: DeviceInstallParams.FlagsEx,
+ hwndParent: DeviceInstallParams.hwndParent,
+ InstallMsgHandler: DeviceInstallParams.InstallMsgHandler,
+ InstallMsgHandlerContext: DeviceInstallParams.InstallMsgHandlerContext,
+ FileQueue: DeviceInstallParams.FileQueue,
+ }
+ _data.Size = uint32(unsafe.Sizeof(*_data))
+
+ driverPathUTF16, err := syscall.UTF16FromString(DeviceInstallParams.DriverPath)
+ if err != nil {
+ return
+ }
+ copy(_data.DriverPath[:], driverPathUTF16)
+
+ return
+}
+
// DI_FLAGS is SP_DEVINSTALL_PARAMS.Flags values
type DI_FLAGS uint32