AutoHotkey Community

It is currently May 26th, 2012, 10:13 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: October 20th, 2009, 1:42 pm 
Offline

Joined: November 1st, 2006, 8:33 pm
Posts: 21
Location: Chicago, IL
The following code worked in 1.0.47.06 but fails in 1.0.48.05 (error handling code not shown). The TextLen is retrieved correctly but the Text variable is empty (because the Temp variable is empty after the call to the FileRead function to retrieve the text).
Code:
;Get length of text in file (including trailing null)
FileRead( handle, Temp, 4 )
TextLen := NumGet( Temp )

;Get text
FileRead( handle, Temp, TextLen )
Text := Temp

;FileRead function
FileRead( handle, ByRef Result, Length )
{
   VarSetCapacity( Result, Length, 0 )
   DllCall( "ReadFile", handle, Result, Length, ... )
}

If I remove the use of the Temp variable when retrieving the text it works fine. For example:
Code:
;Get length of text in file (including trailing null)
FileRead( handle, Temp, 4 )
TextLen := NumGet( Temp )

;Get text
FileRead( handle, Text, TextLen )

It appears that AHK doesn't like the fact that the Temp variable was previously used to get the text length before it was filled with the null terminated text string.

[ Moderator!: Moved from Bug Reports ]


Report this post
Top
 Profile  
Reply with quote  
PostPosted: October 22nd, 2009, 4:01 pm 
Offline

Joined: November 1st, 2006, 8:33 pm
Posts: 21
Location: Chicago, IL
Problem was fixed by making the following change to the ReadFile dll call:

From:
Code:
RtnCode := DllCall( "ReadFile", "UInt", Handle, "UInt", &TextRead, ... )

To:
Code:
RtnCode := DllCall( "ReadFile", "UInt", Handle, "Str", TextRead, ... )

Apparently, the pointer to the variable to receive the result needs to be specified as a "Str" instead of passing an address to the variable with "UInt".


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 22nd, 2009, 5:40 pm 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8776
This would also work:
Code:
VarSetCapacity( TextRead, Length, 32 )
RtnCode := DllCall( "ReadFile", "UInt", Handle, "UInt", &TextRead, ... )


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: hyper_, JSLover, Leef_me, oldbrother, patgenn123 and 63 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group