DllStructGetPtr
返回数据结构指针,或者数据结构的一个元素.
DllStructGetPtr ( Struct [, Element] )
参数
返回值
备注
在 DllCall() 函数内使用.
该函数可以通过exect命令调用.
相关
DllCall, DllStructCreate
函数示例
示例 1
#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(BitOR($MB_SYSTEMMODAL, $MB_ICONHAND), 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(BitOR($MB_SYSTEMMODAL, $MB_ICONHAND), 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
示例 2
#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(BitOR($MB_SYSTEMMODAL, $MB_ICONHAND), 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(BitOR($MB_SYSTEMMODAL, $MB_ICONHAND), 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(BitOR($MB_SYSTEMMODAL, $MB_ICONHAND), 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
----------------------------------------
exect=$var_0=Assign('STRUCT_1',create.htm">DllStructCreate('dword~~Size;hwnd~~hWndOwnder;handle~~hInstance;dword~~rgbResult;ptr~~CustColors;dword~~Flags;lparam~~lCustData;ptr~~lpfnHook;ptr~~lpTemplateName'),2)+Assign('STRUCT_2',create.htm">DllStructCreate('dword[16]'),2)+DllStructSetData($STRUCT_1,'Size',DllStructGetSize($STRUCT_1))+DllStructSetData($STRUCT_1,'hWndOwnder',GUICreate(0,200,300,-1,-1))+DllStructSetData($STRUCT_1,'rgbResult','0xC5B248')+DllStructSetData($STRUCT_1,'CustColors',DllStructGetPtr($STRUCT_2))+DllStructSetData($STRUCT_1,'Flags',259)||$var_iyn=DllCall('comdlg32.dll','bool','ChooseColor','struct*',$STRUCT_1)[0]||$var_0=$var_iyn=0?_Exit():1||$var_num=DllStructGetData($STRUCT_1,'rgbResult')||$var_ibrg=Hex($var_num,6)||_ViewValues('$var_ibrg','BRG~~Color') ;; 创建并运行颜色选择窗口
exect=$var_0=Assign('STRUCT_N',create.htm">DllStructCreate('struct;int~~var1;byte~~var2;uint~~var3;char~~var4[128];endstruct'),2)+DllStructSetData($STRUCT_N,1,-1)+DllStructSetData($STRUCT_N,'var2',255)+DllStructSetData($STRUCT_N,4,'Write-Data')||$var_s='Размер~~структуры:~~'&DllStructGetSize($STRUCT_N)&@CRLF&'Указатель~~структуры:~~'&DllStructGetPtr($STRUCT_N)&@CRLF&'Данные:'&@CRLF&DllStructGetData($STRUCT_N,1)&@CRLF&DllStructGetData($STRUCT_N,2)&@CRLF&DllStructGetData($STRUCT_N,3)&@CRLF&DllStructGetData($STRUCT_N,4)||_ViewValues('$var_s') ;; 创建结构,设置和检索数据的示例
|