I am trying to call MsiEnumProductsExW. The problem I am running into is that the for
-loop below never exits. My assumption is that my err == windows.ERROR_NO_MORE_ITEMS
is wrong.
My code:
var (
msiDLL = syscall.NewLazyDLL("msi.dll")
procMsiEnumProductsExW = msiDLL.NewProc("MsiEnumProductsExW")
)
func getMsiSoftware() (/*redacted*/, error) {
var index uint32 = 0
var bufSize uint32 = 39 // GUID length (including terminating nul character)
productCode := make([]uint16, bufSize)
for {
_, _, err := procMsiEnumProductsExW.Call(
uintptr(0),
uintptr(0),
uintptr(0),
uintptr(index),
uintptr(unsafe.Pointer(&productCode[0])),
uintptr(0),
uintptr(0),
uintptr(0),
)
if err == windows.ERROR_SUCCESS {
// For the same of a minimal reproducible example, I don't do anything with
// productCode right now
index++
} else if err == windows.ERROR_MORE_DATA {
// Increase buffer size if needed and call again
productCode = make([]uint16, bufSize*2)
} else if err == windows.ERROR_NO_MORE_ITEMS {
break
} else {
return nil, fmt.Errorf("retrieving MSI product codes failed")
}
}
return nil, nil // Satisfy the compiler
}
How can I correct my logic to correctly check if the MsiEnumProductsExW
returns ERROR_NO_MORE_ITEMS
?