From bd963497da908d3910668dab9dab4ac7654a638a Mon Sep 17 00:00:00 2001 From: Simon Rozman Date: Thu, 7 Feb 2019 22:35:03 +0100 Subject: setupapi: Merge _SP_DEVINSTALL_PARAMS and DevInstallParams Signed-off-by: Simon Rozman --- tun/wintun/setupapi/types_windows.go | 51 ++++++++---------------------------- 1 file changed, 11 insertions(+), 40 deletions(-) (limited to 'tun/wintun/setupapi/types_windows.go') diff --git a/tun/wintun/setupapi/types_windows.go b/tun/wintun/setupapi/types_windows.go index a37fdec..ae60bd0 100644 --- a/tun/wintun/setupapi/types_windows.go +++ b/tun/wintun/setupapi/types_windows.go @@ -123,8 +123,9 @@ const ( DIF_FINISHINSTALL_ACTION DI_FUNCTION = 0x0000002A ) -type _SP_DEVINSTALL_PARAMS struct { - Size uint32 +// DevInstallParams is device installation parameters structure (associated with a particular device information element, or globally with a device information set) +type DevInstallParams struct { + size uint32 Flags DI_FLAGS FlagsEx DI_FLAGSEX hwndParent uintptr @@ -133,50 +134,20 @@ type _SP_DEVINSTALL_PARAMS struct { FileQueue HSPFILEQ _ uintptr _ uint32 - 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[:]), - } + driverPath [windows.MAX_PATH]uint16 } -// 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 +func (params *DevInstallParams) GetDriverPath() string { + return windows.UTF16ToString(params.driverPath[:]) } -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) +func (params *DevInstallParams) SetDriverPath(driverPath string) error { + str, err := syscall.UTF16FromString(driverPath) if err != nil { - return + return err } - copy(_data.DriverPath[:], driverPathUTF16) - - return + copy(params.driverPath[:], str) + return nil } // DI_FLAGS is SP_DEVINSTALL_PARAMS.Flags values -- cgit v1.2.3-59-g8ed1b