Let's see what struct type is, why it's added and how to use it. struct is type identifier for parameters passed to DllCall() function and objects created with ObjectCreateInterface(). It tells AutoIt that parameter is to be interpreted as structure (composite type). Essentially x64 systems (100 years ago) brought the need for this kind of identifier. More specifically the need for non-compiled scripts to be equally runnable both with/thru 64bit and 32bit version of the interpreter. This is one of three main rules for every good AutoIt script. To show proper usage I'll use two examples. One is for struct* and other for struct. struct* is, as said already used when you want to pass structure pointer. Previously you would use ptr type and function DllStructGetPtr($tSTRUCT). Not to create confusion of some sort you can still use that method, only it's recommended that you do something like this: _Example1(64 + 262144, "Caption", "Some text to display.")
Func _Example1($iFlag, $sCaption, $sText)
; Some sub-structures required by the main structure below. Don't let this catch your eye.
Local $tTEXT = DllStructCreate("wchar[" & StringLen($sText) + 1 & "]")
DllStructSetData($tTEXT, 1, $sText)
Local $tCAPTION = DllStructCreate("wchar[" & StringLen($sCaption) + 1 & "]")
DllStructSetData($tCAPTION, 1, $sCaption)
; Create the main structure
Local $tMSGBOXPARAMS = DllStructCreate("uint cbSize;" & _
"hwnd hwndOwner;" & _
"handle hInstance;" & _
"ptr lpszText;" & _
"ptr lpszCaption;" & _
"dword dwStyle;" & _
"ptr lpszIcon;" & _
"dword_ptr dwContextHelpId;" & _
"ptr lpfnMsgBoxCallback;" & _
"dword dwLanguageId;")
; Fill it
DllStructSetData($tMSGBOXPARAMS, "cbSize", DllStructGetSize($tMSGBOXPARAMS))
DllStructSetData($tMSGBOXPARAMS, "lpszText", DllStructGetPtr($tTEXT))
DllStructSetData($tMSGBOXPARAMS, "lpszCaption", DllStructGetPtr($tCAPTION))
DllStructSetData($tMSGBOXPARAMS, "dwStyle", $iFlag)
; Call passing struct for "struct*" parameter type
Local $aCall = DllCall("user32.dll", "int", "MessageBoxIndirectW", "struct*", $tMSGBOXPARAMS)
If @error Then Return SetError(1, 0, -1)
Return $aCall[0]
EndFunc Another example is using struct type. This is where the whole magic is seen. Without struct type you are forced to use different workarounds not to cause stack corruption when your code is run with interpreter of wrong bitness. Now you can elegantly push a blody structure as parameter: ConsoleWrite(WinGetTitle(_Example2(10, 10)) & @CRLF)
Func _Example2($iX, $iY)
; Create structure
Local $tPOINT = DllStructCreate("long x; long y")
DllStructSetData($tPOINT, "x", $iX)
DllStructSetData($tPOINT, "y", $iY)
; DllCall passing struct for "struct" param type
Local $aCall = DllCall("user32.dll", "hwnd", "WindowFromPoint", "struct", $tPOINT)
If @error Then Return SetError(1)
Return $aCall[0]
EndFunc Anyway, this is how different scenarios are handled: Parameter description: Parameter type: Action:
- "struct" - dllstruct - accept and process sruct
- "struct" - non-dllstruct - error is raised
- "struct*" - dllstruct - pointer to dllstruct is read internally
- "struct*" - non-dllstruct - parameter is taken to be dllstruct pointer As I said, the same thing applies to objects created with ObjCreateInterface, called InterfaceDispatch objects. Their description string can include struct and struct* type identifiers.