From c4988999ac073db9e08a4efdb2f82a3d4f32f25d Mon Sep 17 00:00:00 2001 From: Simon Rozman Date: Thu, 7 Feb 2019 23:45:11 +0100 Subject: setupapi: Merge _SP_DRVINFO_DETAIL_DATA and DrvInfoDetailData Signed-off-by: Simon Rozman --- tun/wintun/setupapi/setupapi_windows.go | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'tun/wintun/setupapi/setupapi_windows.go') diff --git a/tun/wintun/setupapi/setupapi_windows.go b/tun/wintun/setupapi/setupapi_windows.go index cc89354..f736af5 100644 --- a/tun/wintun/setupapi/setupapi_windows.go +++ b/tun/wintun/setupapi/setupapi_windows.go @@ -146,36 +146,38 @@ func (deviceInfoSet DevInfo) SetSelectedDriver(deviceInfoData *DevInfoData, driv return SetupDiSetSelectedDriver(deviceInfoSet, deviceInfoData, driverInfoData) } -//sys setupDiGetDriverInfoDetail(deviceInfoSet DevInfo, deviceInfoData *DevInfoData, driverInfoData *DrvInfoData, driverInfoDetailData *_SP_DRVINFO_DETAIL_DATA, driverInfoDetailDataSize uint32, requiredSize *uint32) (err error) = setupapi.SetupDiGetDriverInfoDetailW +//sys setupDiGetDriverInfoDetail(deviceInfoSet DevInfo, deviceInfoData *DevInfoData, driverInfoData *DrvInfoData, driverInfoDetailData *DrvInfoDetailData, driverInfoDetailDataSize uint32, requiredSize *uint32) (err error) = setupapi.SetupDiGetDriverInfoDetailW // SetupDiGetDriverInfoDetail function retrieves driver information detail for a device information set or a particular device information element in the device information set. -func SetupDiGetDriverInfoDetail(deviceInfoSet DevInfo, deviceInfoData *DevInfoData, driverInfoData *DrvInfoData) (driverInfoDetailData *DrvInfoDetailData, err error) { +func SetupDiGetDriverInfoDetail(deviceInfoSet DevInfo, deviceInfoData *DevInfoData, driverInfoData *DrvInfoData) (*DrvInfoDetailData, error) { const bufCapacity = 0x800 buf := [bufCapacity]byte{} var bufLen uint32 - _data := (*_SP_DRVINFO_DETAIL_DATA)(unsafe.Pointer(&buf[0])) - _data.Size = uint32(unsafe.Sizeof(*_data)) + data := (*DrvInfoDetailData)(unsafe.Pointer(&buf[0])) + data.size = uint32(unsafe.Sizeof(*data)) - err = setupDiGetDriverInfoDetail(deviceInfoSet, deviceInfoData, driverInfoData, _data, bufCapacity, &bufLen) + err := setupDiGetDriverInfoDetail(deviceInfoSet, deviceInfoData, driverInfoData, data, bufCapacity, &bufLen) if err == nil { // The buffer was was sufficiently big. - return _data.toGo(bufLen), nil + data.size = bufLen + return data, nil } if errWin, ok := err.(syscall.Errno); ok && errWin == windows.ERROR_INSUFFICIENT_BUFFER { // The buffer was too small. Now that we got the required size, create another one big enough and retry. buf := make([]byte, bufLen) - _data := (*_SP_DRVINFO_DETAIL_DATA)(unsafe.Pointer(&buf[0])) - _data.Size = uint32(unsafe.Sizeof(*_data)) + data := (*DrvInfoDetailData)(unsafe.Pointer(&buf[0])) + data.size = uint32(unsafe.Sizeof(*data)) - err = setupDiGetDriverInfoDetail(deviceInfoSet, deviceInfoData, driverInfoData, _data, bufLen, &bufLen) + err = setupDiGetDriverInfoDetail(deviceInfoSet, deviceInfoData, driverInfoData, data, bufLen, &bufLen) if err == nil { - return _data.toGo(bufLen), nil + data.size = bufLen + return data, nil } } - return + return nil, err } // GetDriverInfoDetail method retrieves driver information detail for a device information set or a particular device information element in the device information set. -- cgit v1.2.3-59-g8ed1b