 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
TL
Joined: 01 Nov 2006 Posts: 17
|
Posted: Tue Oct 20, 2009 12:42 pm Post subject: Variable empty using DllCall( "Readfile" ... |
|
|
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 ] |
|
| Back to top |
|
 |
TL
Joined: 01 Nov 2006 Posts: 17
|
Posted: Thu Oct 22, 2009 3:01 pm Post subject: User error - Variable empty using DllCall( "Readfile&qu |
|
|
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". |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 7159
|
Posted: Thu Oct 22, 2009 4:40 pm Post subject: |
|
|
This would also work:
| Code: | VarSetCapacity( TextRead, Length, 32 )
RtnCode := DllCall( "ReadFile", "UInt", Handle, "UInt", &TextRead, ... ) |
|
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|