Returns the pointer to the struct or an element in the struct.
DllStructGetPtr ( Struct [, Element] )
Struct | The struct returned by DllStructCreate(). |
Element | [optional] The element of the struct whose pointer you need, starting at 1 or the element name as defined in DllStructCreate(). |
Success: | The pointer to the struct. |
Failure: | 0. |
@error: | 1 = Struct not a valid struct returned by DllStructCreate(). 2 = Element out of range. |
Used in DllCall().
#include <MsgBoxConstants.au3>
#include <StructureConstants.au3>
Example()
Func Example()
; Assign a Local variable the handle of the current active window.
Local $hWnd = WinGetHandle("") ; Same as: "[active]".
; Assign a Local variable the window's rectangle (array).
Local $aWndPos = WinGetPos($hWnd)
; Assign a Local variable the structure created with the tagRECT definition.
Local $tRECT = DllStructCreate($tagRECT)
Local $iError = 0
; If an error occurred display the error code and return False.
If @error Then
$iError = @error
MsgBox(($MB_ICONERROR + $MB_SYSTEMMODAL), Default, "Error in DllStructCreate, Code: " & $iError)
Return False
EndIf
; Make the DllCall of the GetWindowRect function.
DllCall("user32.dll", "int", "GetWindowRect", _
"hwnd", $hWnd, _
"ptr", DllStructGetPtr($tRECT))
; If an error occurred display the error code and return False.
If @error Then
$iError = @error
MsgBox(($MB_ICONERROR + $MB_SYSTEMMODAL), Default, "Error in DllCall, Code: " & $iError)
Return False
EndIf
; Note: The 2nd parameter of the GetWindowRect function requires a pointer,
; the result returned by the DllStructCreate is NOT a pointer, but using 'struct*' allows to pass a structure as a ptr.
; Assign Local variables the returned rectangle.
Local $iLeft = DllStructGetData($tRECT, "Left") ; Or 1 instead of "Left".
Local $iTop = DllStructGetData($tRECT, 2) ; Or "Top" instead of 2.
Local $iRight = DllStructGetData($tRECT, 3) ; Or "Right" instead of 3.
Local $iBottom = DllStructGetData($tRECT, "Bottom") ; Or 4 instead of "Bottom".
; Release the resources used by the structure.
$tRECT = 0
; Display the results of WinGetPos and the returned rectangle.
MsgBox($MB_SYSTEMMODAL, "", "WinGetPos(): (" & $aWndPos[0] & ", " & $aWndPos[1] & ") " & _
"(" & $aWndPos[2] + $aWndPos[0] & ", " & $aWndPos[3] + $aWndPos[1] & ")" & @CRLF & _
"GetWindowRect(): (" & $iLeft & ", " & $iTop & ") (" & $iRight & ", " & $iBottom & ")")
EndFunc ;==>Example
#include <MsgBoxConstants.au3>
Example()
Func Example()
; Assign a Local variable a structure with the definition of an int.
Local $tSTRUCT1 = DllStructCreate("int")
Local $iError = 0
; If an error occurred display the error code and return False.
If @error Then
$iError = @error
MsgBox(($MB_ICONERROR + $MB_SYSTEMMODAL), Default, "Error in DllCall, Code: " & $iError)
Return False
EndIf
; Assign a Local variable the tSTRUCT1 structure except that the elements will be got according to the new definition.
Local $tSTRUCT2 = DllStructCreate("uint", DllStructGetPtr($tSTRUCT1, 1))
; If an error occurred display the error code and return False.
If @error Then
$iError = @error
MsgBox(($MB_ICONERROR + $MB_SYSTEMMODAL), Default, "Error in DllCall, Code: " & $iError)
Return False
EndIf
Local $tSTRUCT3 = DllStructCreate("float", DllStructGetPtr($tSTRUCT1, 1))
; If an error occurred display the error code and return False.
If @error Then
$iError = @error
MsgBox(($MB_ICONERROR + $MB_SYSTEMMODAL), Default, "Error in DllCall, Code: " & $iError)
Return False
EndIf
; Notes: -The structures points to the same structure (they have the same pointer);
; The first element got with the:
; *tSTRUCT1 struct will be an int.
; *tSTRUCT2 struct will be an unsigned int (the element is casted from int to uint).
; *tSTRUCT3 struct will be a float (the element is casted from int to float).
;
; -The "reinterpret_cast" casting operator is used.
; Set the data of the first element (int) in the $tSTRUCT1.
DllStructSetData($tSTRUCT1, 1, -1)
; Display the different data types of the same data.
MsgBox($MB_SYSTEMMODAL, "", _
"int: " & DllStructGetData($tSTRUCT1, 1) & @CRLF & _
"uint: " & DllStructGetData($tSTRUCT2, 1) & @CRLF & _
"float: " & DllStructGetData($tSTRUCT3, 1))
; Release the resources used by the structures.
$tSTRUCT1 = 0
$tSTRUCT2 = 0
$tSTRUCT3 = 0
EndFunc ;==>Example