When using Numget inside the function CheckBytes, it returns mostly wrong values.
The following testscript fills all bytes in bitList with initValue, but Numget reads some other values.
The GetIntAt() function reads always the correct initValue though.
Is there a way to get it right with NumGet in a function?
Code:
showEveryByte := true ; false avoids checking every byte by user
byteCount := 64 , initValue := 123
GrantedCapacity := VarSetCapacity(bitList, byteCount, initValue)
CheckBytes(&bitList, GrantedCapacity) ; test for NumGet in function
; If not in a function, NumGet never causes a problem:
Loop %GrantedCapacity% {
byteNumber := A_index - 1
numByte := NumGet(&bitList, byteNumber, "char")
intByte := GetIntAt(&bitList, byteNumber, 1)
if (showEveryByte || numByte <> initValue || intByte <> initValue){
msgbox, 1, Outside: byte %byteNumber% (V%A_AhkVersion%)
, numByte= %numByte% `nintByte= %intByte% `n(initValue= %initValue%)
IfMsgBox, Cancel
break
}
}
VarSetCapacity(bitList, 0) ; free bitList
ExitApp
F9::ExitApp
return
CheckBytes(pBitList, GrantedCapacity){
; W/ NumGet in a function, it causes always a problem at some byte(s)
global showEveryByte, initValue
Loop %GrantedCapacity% {
byteNumber := A_index - 1
numByte := NumGet(pBitList, byteNumber, "char") ; pBitList or *pBitList does NOT work for me
intByte := GetIntAt(pBitList, byteNumber, 1)
if (showEveryByte || (numByte <> initValue) || (intByte <> initValue)){
msgbox, 1, Inside: byte %byteNumber% (V%A_AhkVersion%)
, numByte= %numByte% `nintByte= %intByte% `n(initValue= %initValue% baseAddress= %pBitList%)
IfMsgBox, Cancel
return
}
}
}
GetIntAt(address, offset, size){ ; replacement for NumGet works always fine
int := 0
Loop %size% {
byteNumber := A_index - 1
int += *(address + offset + byteNumber) << (8 * byteNumber)
}
return int
}