创建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

 

你可能感兴趣的:(struct)