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

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
newbieforever
Posts: 493
Joined: 24 Aug 2016, 03:34

How to use RawRead (a newbie question)

13 May 2019, 04:43

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()
Osprey
Posts: 453
Joined: 18 Nov 2017, 05:50

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

13 May 2019, 05:15

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.
newbieforever
Posts: 493
Joined: 24 Aug 2016, 03:34

Re: How to use RawRead (a newbie question)

14 May 2019, 08:48

Thank you, Osprey! Of course, yes... In my real script the Size was defined, but was not a global variable...

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Exies, hiahkforum and 123 guests