StrGet()

Author: Lexikos Last Modified: 20100629


Copies a string from a memory address, optionally converting it between code pages. Behaviour should be identical to their built-in counterparts in AutoHotkey_L.

License

The functions is an open source item under the Public Domain license.
For details, please see lexikos-license.txt

Example

; #Include strPut.ahk
; #Include strGet.ahk
#NoEnv
SendMode Input
SetWorkingDir %A_ScriptDir%

input := ""
output := ""

; Write the string "Hello World!" into variable with default ANSI code page.
; Display how many characters are written.
MsgBox % StrPutVar("Hello World!", input, "cp0")

; Get string from adress of variable "input" with default ANSI code page.
output := StrGet(&input, "cp0")

; Display the output string.
MsgBox %output%

; If you use frequently StrPut() with variables, consider to add this function.
; Function copied from StrPutGet-documentation written by Lexikos.
StrPutVar(string, ByRef var, encoding)
{
    ; Ensure capacity.
    VarSetCapacity( var, StrPut(string, encoding)
        ; StrPut returns char count, but VarSetCapacity needs bytes.
        * ((encoding="utf-16"||encoding="cp1200") ? 2 : 1) )
    ; Copy or convert the string.
    return StrPut(string, &var, encoding)
}