Function Reference

首页  后退  前进

DllStructGetData

 

返回数据结构的元素数据.

 

DllStructGetData ( Struct, Element [, index = Default] )

参数

Struct

DllStructCreate() 返回的数据结构.

Element

要访问的数据结构元素, 起始于 1 或是 DllStructCreate() 函数定义的元素名.

index

[可选] 对于数组元素, 需指定基于 1 的元素索引.

如果省略或 Default(默认)关键字, 则检索整个数组 (用于快速检索字符串).

不能用于非数组元素

 

返回值

成功:

返回数据结构的元素数据.

失败:

返回 0.

@error:

1 = DllStructCreate() 函数返回的数据结构不正确.

2 = 元素值超出范围或未知.

3 = 索引值超出范围.

4 = 元素的数据类型未知

5 = 索引 <= 0.

备注

当元素为 char[n] 或 wchar[n], wchar 或 wchar[n] 返回的数据始终是 String(),

当元素为 byte[n], 并且索引被省略时, 返回数据是二进制类型,

否则总是返回最合适 AutoIt 对应元素的数据类型 (例如, 字节返回 Int32, 浮动值返回双精度).

 

该函数可以通过exect命令调用.

 

相关

DllStructCreate, DllStructSetData

函数示例

#include <MsgBoxConstants.au3>
Example()
Func Example()
    #cs Comments:
    Create the following structure (C language):
    struct {
        int var1;
        unsigned char var2;
        unsigned int var3;
        char var4[128];
    };
    Schema:
    ------------------------------------
    \ int    \ byte   \ uint   \ char   \
     \   var1 \   var2 \   var3 \   var4 \
      ------------------------------------
    #ce
    ; Assign a Local constant variable the definition of a structure (read carefully the DllStructCreate remarks).
    Local Const $tagSTRUCT1 = "struct;int var1;byte var2;uint var3;char var4[128];endstruct"
    ; Note: The tag variable is declared as Constant because its value will never change for any script execution.
    ; Assign a Local variable the structure.
    Local $tSTRUCT1 = DllStructCreate($tagSTRUCT1)
    ; If an error occurred display the error code and return False.
    If @error Then
        MsgBox($MB_SYSTEMMODAL, "", "Error in DllStructCreate, Code: " & @error)
        Return False
    EndIf
    ; Set the data of the element var1 (int) in the $tSTRUCT1.
    DllStructSetData($tSTRUCT1, "var1", -1) ; Or 1 instead of "var1".
    ; Set the data of the element var2 (byte) in the $tSTRUCT1.
    DllStructSetData($tSTRUCT1, 2, 255) ; Or "var2" instead of 2.
    ; Set the data of the element var3 (uint) in the $tSTRUCT1.
    DllStructSetData($tSTRUCT1, "var3", -1) ; The -1 (signed int) will be typecasted to unsigned int.
    ; Or 3 instead of "var3".
    ; Set the data of the element var4 (char) in the $tSTRUCT1.
    DllStructSetData($tSTRUCT1, "var4", "Hello") ; Or 4 instead of "var4".
    ; Note: This element can contain up to 128 characters.
    ; Change the data of the element var4 (char) in the $tSTRUCT1, at the index 1 of the char array (1 based index).
    DllStructSetData($tSTRUCT1, "var4", Asc("h"), 1)
    ; Display the results.
    MsgBox($MB_SYSTEMMODAL, "", "Struct Size: " & DllStructGetSize($tSTRUCT1) & @CRLF & _
            "Struct pointer: " & DllStructGetPtr($tSTRUCT1) & @CRLF & _
            "Data:" & @CRLF & _
            DllStructGetData($tSTRUCT1, 1) & @CRLF & _ ; Or "var1" instead of 1.
            DllStructGetData($tSTRUCT1, "var2") & @CRLF & _ ; Or 2 instead of "var2".
            DllStructGetData($tSTRUCT1, 3) & @CRLF & _ ; Or "var3" instead of 3.
            DllStructGetData($tSTRUCT1, 4)) ; Or "var4" instead of 4.
    ; Release the resources used by the structure.
    $tSTRUCT1 = 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') ;; 创建结构,设置和检索数据的示例

 

exect=$var_handle=WinGetHandle('[CLASS:TTOTAL_CMD]')||$var_0=Assign('STRUCT_RECT',create.htm">DllStructCreate(':tagRECT:'),2)+DllCall('user32.dll','bool','GetWindowRect','hwnd',Eval('var_handle'),'struct*',$STRUCT_RECT)||$var_s='Координаты~~углов~~TC:'&@CRLF&'X1:~~'&DllStructGetData($STRUCT_RECT,'Left')&@CRLF&'X2:~~'&DllStructGetData($STRUCT_RECT,'Right')&@CRLF&'Y1:~~'&DllStructGetData($STRUCT_RECT,'Top')&@CRLF&'Y2:~~'&DllStructGetData($STRUCT_RECT,'Bottom')||_ViewValues('$var_s') ;; 获取Total Commander窗口的坐标

 

exect=$var_0=Assign('STRUCT_ICON',create.htm">DllStructCreate('int'),2)+Assign('STRUCT_STRING',create.htm">DllStructCreate('wchar[260]'),2)+DllStructSetData($STRUCT_STRING,1,@SystemDir&'\shell32.dll')||$var_iyn=DllCall('shell32.dll','int',62,'hwnd',GUICreate(0,400,400,-1,-1),'struct*',$STRUCT_STRING,'int',DllStructGetSize($STRUCT_STRING)/2,'struct*',$STRUCT_ICON)[0]||$var_0=$var_iyn=0?_Exit():1||$var_s=DllStructGetData($STRUCT_STRING,1)&','&DllStructGetData($STRUCT_ICON,1)||_ViewValues('$var_s','Путь~~и~~номер~~значка') ;; 在系统对话框中选择一个图标