Code: Select all
nSize := VarSetCapacity(lpFilename, 512, 0)
DllCall("GetModuleFileName", "Ptr", 0, "Ptr", &lpFilename, "UInt", nSize)
MsgBox % "|" StrGet(&lpFilename) "|`n|" StrGet(&lpFilename, 256) "|"
Code: Select all
nSize := VarSetCapacity(lpFilename, 512, 0)
DllCall("GetModuleFileName", "Ptr", 0, "Ptr", &lpFilename, "UInt", nSize)
MsgBox % "|" StrGet(&lpFilename) "|`n|" StrGet(&lpFilename, 256) "|"
If the function succeeds, the return value is the length of the string that is copied to the buffer, in characters, not including the terminating null character.
As implemented, it seems that Length represents the actual number of characters. That confused me.LengthThe maximum number of characters to read/write, including the null-terminator if required. See Return Value.
Code: Select all
nSize := VarSetCapacity(lpFilename, 512, 0)
nSize := DllCall("GetModuleFileName", "Ptr", 0, "Ptr", &lpFilename, "UInt", nSize)
String1 := StrGet(&lpFilename, nSize) ; C:\Program Files\AutoHotkey\AutoHotkey.exe
String2 := StrGet(&lpFilename, 256)
MsgBox % StrLen(String1) " vs " StrLen(String2) ; 42 vs 256
v2.0-a075-02fab78
Changed StrGet to truncate the string at the first binary zero (null terminator), as in v1. Specifying a negative Length now causes it to extract exactly Abs(Length) characters (as previous builds did for positive values), utilizing v2's support for binary zero in strings.
Return to “AutoHotkey Development”
Users browsing this forum: No registered users and 22 guests