DllStructSetData
设置结构元素的数据.
DllStructSetData ( Struct, Element, value [, index] )
参数
Struct
|
Html.html.fun 返回的数据结构.
|
Element
|
基于 1 的结构元素, 或是 DllStructCreate() 函数定义的元素名称.
|
value
|
设置结构元素的新值.
|
index
|
[可选] 对于数组元素,需要指定基于 1 的索引.
如果省略或 Default(默认)关键字, 将设置索引基于 1 的尽可能多的值 (用于快速设置字符串).
不用于非数组元素.
|
返回值
成功:
|
返回从数据结构读取的值.
|
失败:
|
返回 0.
|
@error:
|
1 = DllStructCreate() 返回的结构不是一个有效的结构.
2 = 元素超出范围或未知.
3 = 索引超出范围.
4 = 元素的数据类型未知
5 = 索引 <= 0.
|
备注
当颜色为 char[n], wchar[n] 或 byte[n] 的数据可以是字符串. byte[n] 也接受二进制数据.
否则数据是与元素兼容的 AutoIt 类型, 或是转换为所需类型的数字.
原生 AutoIt 字符串隐含转换为 ANSI 之前复制的 char[n] 或 byte[n] 元素. 当元素期望这种编码(例如在 DllCall 中), 需要将原生 Unicode 字符串转换为 UTF8.
该函数可以通过exect命令调用.
相关
DllStructCreate, DllStructGetData, DllStructGetSize
函数示例
#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_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','Путь~~и~~номер~~значка') ;; 在系统对话框中选择一个图标
|