diff --git a/setupapi/setupapi_windows.go b/setupapi/setupapi_windows.go index 67793b2..95c5ba6 100644 --- a/setupapi/setupapi_windows.go +++ b/setupapi/setupapi_windows.go @@ -122,9 +122,11 @@ func SetupDiGetDeviceInfoListDetail(DeviceInfoSet DevInfo) (data *DevInfoListDet } // SetupDiEnumDeviceInfo function returns a SP_DEVINFO_DATA structure that specifies a device information element in a device information set. -func SetupDiEnumDeviceInfo(DeviceInfoSet DevInfo, MemberIndex int, data *SP_DEVINFO_DATA) error { - data.Size = uint32(unsafe.Sizeof(*data)) - return setupDiEnumDeviceInfo(DeviceInfoSet, uint32(MemberIndex), data) +func SetupDiEnumDeviceInfo(DeviceInfoSet DevInfo, MemberIndex int) (DeviceInfoData *SP_DEVINFO_DATA, err error) { + data := SP_DEVINFO_DATA{} + data.Size = uint32(unsafe.Sizeof(data)) + + return &data, setupDiEnumDeviceInfo(DeviceInfoSet, uint32(MemberIndex), &data) } // SetupDiOpenDevRegKey function opens a registry key for device-specific configuration information. diff --git a/setupapi/setupapi_windows_test.go b/setupapi/setupapi_windows_test.go index 5d84a39..76257ac 100644 --- a/setupapi/setupapi_windows_test.go +++ b/setupapi/setupapi_windows_test.go @@ -146,9 +146,8 @@ func TestSetupDiEnumDeviceInfo(t *testing.T) { } defer devInfoList.Close() - var data SP_DEVINFO_DATA for i := 0; true; i++ { - err := SetupDiEnumDeviceInfo(devInfoList, i, &data) + data, err := SetupDiEnumDeviceInfo(devInfoList, i) if err != nil { if errWin, ok := err.(syscall.Errno); ok && errWin == 259 /*ERROR_NO_MORE_ITEMS*/ { break @@ -169,9 +168,8 @@ func TestSetupDiOpenDevRegKey(t *testing.T) { } defer devInfoList.Close() - var data SP_DEVINFO_DATA for i := 0; true; i++ { - err := SetupDiEnumDeviceInfo(devInfoList, i, &data) + data, err := SetupDiEnumDeviceInfo(devInfoList, i) if err != nil { if errWin, ok := err.(syscall.Errno); ok && errWin == 259 /*ERROR_NO_MORE_ITEMS*/ { break @@ -179,7 +177,7 @@ func TestSetupDiOpenDevRegKey(t *testing.T) { continue } - key, err := SetupDiOpenDevRegKey(devInfoList, &data, DICS_FLAG_GLOBAL, 0, DIREG_DRV, windows.KEY_READ) + key, err := SetupDiOpenDevRegKey(devInfoList, data, DICS_FLAG_GLOBAL, 0, DIREG_DRV, windows.KEY_READ) if err != nil { t.Errorf("Error calling SetupDiOpenDevRegKey: %s", err.Error()) } @@ -194,9 +192,8 @@ func TestSetupDiGetDeviceInstallParams(t *testing.T) { } defer devInfoList.Close() - var data SP_DEVINFO_DATA for i := 0; true; i++ { - err := SetupDiEnumDeviceInfo(devInfoList, i, &data) + data, err := SetupDiEnumDeviceInfo(devInfoList, i) if err != nil { if errWin, ok := err.(syscall.Errno); ok && errWin == 259 /*ERROR_NO_MORE_ITEMS*/ { break @@ -204,7 +201,7 @@ func TestSetupDiGetDeviceInstallParams(t *testing.T) { continue } - _, err = SetupDiGetDeviceInstallParams(devInfoList, &data) + _, err = SetupDiGetDeviceInstallParams(devInfoList, data) if err != nil { t.Errorf("Error calling SetupDiOpenDevRegKey: %s", err.Error()) }