Page 1 of 1

How to use RawRead (a newbie question)

Posted: 13 May 2019, 04:43
by newbieforever
Hi!

I just can't figure out why this isn't working. The file which should be read is present, not open in another program or running, but the RawRead fails:

MsgBox II shows the correct length. In the case of an exe (Lux.exe) MsgBox III shows 0; in the case of a txt (Text.txt) MsgBox III is not shown at all.

Code: Select all

FileP := A_ScriptDir . "\Lux.exe"   
; FileP := A_ScriptDir . "\Text.txt"

FileGetSize, FileS, %FileP%
MsgBox (I) FileS: %FileS%

VarSetCapacity(Data, Size)
Offset := 0 , oF := "" , oF.Length := 0

If !oF := FileOpen(FileP, "r")
   Return
oF.Pos := 0
Len := oF.Length
MsgBox (II) Len: %Len%
Bytes := oF.RawRead(&Data+Offset, Len)
MsgBox (III) Bytes: %Bytes%
Offset += Len
oF.Close()

Re: How to use RawRead (a newbie question)  Topic is solved

Posted: 13 May 2019, 05:15
by Osprey
You don't have Size defined anywhere, so it's equal to 0 when VarSetCapacity() uses it, which makes Data too small of a variable. I think that what you meant to do was VarSetCapacity(Data, FileS), was it not? That makes your code work.

Re: How to use RawRead (a newbie question)

Posted: 14 May 2019, 08:48
by newbieforever
Thank you, Osprey! Of course, yes... In my real script the Size was defined, but was not a global variable...