创建一个 C/C++ 样式的数据结构供 DllCall 使用.
DllStructCreate ( Struct [,Pointer] )
| Struct | 用字符串来表示的要创建的数据结构.(见 注释). |
| 指针 | [可选参数] 如果指定的数据结构不能分配内存,则使用此指针参数. |
| 成功: | 返回一个供 DllStruct 调用的变量. |
| 失败: | 0 . |
| @Error: | 0 = 没有错误. |
| 1 = 传递给 DllStructCreate 的变量不是一个字符串. | |
| 2 = 传递的字符串中有一个未知的数据类型. | |
| 3 = 为数据结构分配需要的内存失败, 或者指针 = 0. | |
| 4 = 为传递的字串分配内存错误. |
| 类型 | 详细信息 |
| BYTE | 8bit(1字节) 带符号字符(signed char) |
| BOOLEAN | 8bit(1字节) 无符号字符(unsigned char) |
| CHAR | 8bit(1字节) ASCII 字符(ASCII char) |
| WCHAR | 16bit(2字节) UNICODE 宽字符(Wide char) |
| short | 16bit(2字节) 带符号整数(signed integer) |
| USHORT | 16bit(2字节) 无符号整数(unsigned integer) |
| WORD | 16bit(2字节) 无符号整数(unsigned integer) |
| int | 32bit(4字节) 带符号整数(signed integer) |
| long | 32bit(4字节) 带符号整数(signed integer) |
| BOOL | 32bit(4字节) 带符号整数(signed integer) |
| UINT | 32bit(4字节) 无符号整数(unsigned integer) |
| ULONG | 32bit(4字节) 无符号整数(unsigned integer) |
| DWORD | 32bit(4字节) 无符号整数(unsigned integer) |
| INT64 | 64bit(8字节) 带符号整数(signed integer) |
| UINT64 | 64bit(8字节) 无符号整数(unsigned integer) |
| ptr | 32/64位 无符号整数(unsigned integer) (依据使用的 x86 或 x64 AutoIt 的版本) |
| HWND | 32bit(4字节) 整数(integer) |
| HANDLE | 32bit(4字节) 整数(integer) |
| float | 32bit(4字节) 浮点指针(floating point) |
| double | 64bit(8字节) 浮点指针(floating point) |
| INT_PTR, LONG_PTR, LRESULT, LPARAM | 32/64位 带符号整数(signed integer) (依据使用的 x86 或 x64 AutoIt 的版本) |
| UINT_PTR, ULONG_PTR, DWORD_PTR, WPARAM | 32/64位 无符号整数(unsigned integer) (依据使用的 x86 或 x64 AutoIt 的版本) |
| STRUCT | The following datatypes will be align according to C declaration rules. See below. |
| ENDSTRUCT | end of the collection datatypes. Padding can occurs see below. |
| ALIGN | n bytes boundary where datatype must be aligned. |
;=========================================================
; 创建数据结构
; struct {
; int var1;
; unsigned char var2;
; unsigned int var3;
; char var4[128];
; }
;=========================================================
Local $str = "int var1;byte var2;uint var3;char var4[128]"
Local $a = DllStructCreate($str)
If @error Then
MsgBox(4096,"","DllStructCreate 发生错误" & @error);
Exit
EndIf
;=========================================================
; 设置数据结构中的数据
; struct.var1 = -1;
; struct.var2 = 255;
; struct.var3 = INT_MAX; -1 将自动确定类型(unsigned int)
; strcpy(struct.var4,"Hello");
; struct.var4[0] = 'h';
;=========================================================
DllStructSetData($a, "var1", -1)
DllStructSetData($a, "var2", 255)
DllStructSetData($a, "var3", -1)
DllStructSetData($a, "var4", "Hello")
DllStructSetData($a, "var4", Asc("h"), 1)
;=========================================================
; 显示数据结构的信息
;=========================================================
MsgBox(4096,"DllStruct","数据结构大小: " & DllStructGetSize($a) & @CRLF & _
"数据结构指针: " & DllStructGetPtr($a) & @CRLF & _
"Data:" & @CRLF & _
DllStructGetData($a, 1) & @CRLF & _
DllStructGetData($a, 2) & @CRLF & _
DllStructGetData($a, 3) & @CRLF & _
DllStructGetData($a, 4))
;=========================================================
; 释放为数据结构分配的内存
;=========================================================
$a = 0