建立struct類型的數組

在autoit中,如何建立相似這樣的數組呢?以下方式,數組的element只是存儲的地址相鄰,因此咱們能夠這樣作數組

$tagMYSTRUCT = "int code; char msg[10];"

$mystruct = ArrayStruct($tagMYSTRUCT, 4)
$fourth_element = getElement($mystruct, 3, $tagMYSTRUCT) ; $fourth_element is an alias of '$mystruct[3]'
DllStructSetData($fourth_element, "code", 3);

DllCall(...., "struct*", $mystruct)


Func ArrayStruct($tagStruct, $numElements)
    $sizeOfMyStruct = DllStructGetSize(DllStructCreate($tagMYSTRUCT)) // assumes end padding is included
    $numElements = 4
    $bytesNeeded = $numElements * $sizeOfMyStruct
    return DllStructCreate("byte[" & $bytesNeeded & "]")
EndFunc


Func GetElement($Struct, $Element, $tagSTRUCT)
   return DllStructCreate($tagSTRUCT, DllStructGetPtr($Struct) + $Element * DllStructGetSize(DllStructCreate($tagStruct)))
EndFunc
相關文章
相關標籤/搜索