BufferAlloc - Syntax & Usage | AutoHotkey v2
https://lexikos.github.io/v2/docs/commands/BufferAlloc.htm
Buffer Object - Definition & Usage | AutoHotkey v2
https://lexikos.github.io/v2/docs/objects/Buffer.htm
Code: Select all
BufferAlloc(Size)
{
return new Buffer(Size)
}
class Buffer
{
;note: Buffer.Data does not handle nulls as AHK v2 does
__New(Size)
{
this.SetCapacity("_buf", Size)
this._size := size
DllCall("ntdll\RtlFillMemory", "Ptr",this.GetAddress("_buf"), "UPtr",Size, "UChar",0)
}
Size
{
get
{
return this._size
}
set
{
if !(value = this._size)
this.SetCapacity("_buf", value)
if (value > this._size)
DllCall("ntdll\RtlFillMemory", "Ptr",this.GetAddress("_buf")+this._size, "UPtr",value-this._size, "UChar",0)
return this._size := value
}
}
Ptr
{
get
{
return this.GetAddress("_buf")
}
set
{
throw Exception("Invalid usage.", -1)
}
}
Data
{
get
{
return StrGet(this.GetAddress("_buf"), this._size/2, "UTF-16")
}
set
{
throw Exception("Invalid usage.", -1)
}
}
__Get(k, Params*)
{
if !(k = "Ptr")
&& !(k = "Size")
throw Exception("Unknown property.", -1)
}
__Set(k, Params*)
{
if !(k = "_size")
&& !(k = "Data")
&& !(k = "Ptr")
&& !(k = "Size")
throw Exception("Unknown property.", -1)
}
__Call(m, Params*)
{
if !(m = "GetAddress")
&& !(m = "SetCapacity")
throw Exception("Unknown method.", -1)
}
}
old versions