The code snippet below depicts the issue.
Code: Select all
;~ ANSI only
VarSetCapacity(string, 8, 0)
DllCall("RtlFillMemory", "Ptr", &string, "UInt", 3, "UChar", Asc("a")&0xff) ; fill in the first 3 bytes with ASCII value of "a"
MsgBox % string ; all good; result is "aaa"
Loop % 8
bin1 .= *(&string+A_Index-1) . "(" . Chr(*(&string+A_Index-1)) . ")" . "_"
MsgBox % bin1 ; all good; 97 97 97 0 => a NULL terminated string
string .= "b" ; append "b" to "aaa"
MsgBox % string ; result is "b" .. why?
Loop % 8
bin2 .= *(&string+A_Index-1) . "(" . Chr(*(&string+A_Index-1)) . ")" . "_"
MsgBox % bin2 ; 98 0 97 0 . "b" was not appended, was simply assigend to string. Why?