DllCallAddress
动态调用特定内存地址的函数.
DllCallAddress ( "return type", address [, type1, param1 [, type n, param n]] )
参数
return type
|
函数的返回类型 (见下文).
|
address
|
函数的地址. 如果这个值无效, 脚本将崩溃!
|
type1
|
[可选参数l] 参数的类型 (见备注).
|
param1
|
[可选参数l] 实际参数 (见备注).
|
type n
|
[可选参数l] 第 n 个参数的类型 (见备注).
|
param n
|
[可选参数l] 第 n 个实际参数 (见备注).
|
有效的类型:
类型
|
描述
|
NONE
|
没有值 (仅适用于有效的返回类型 - 相当于 C 中的 void )
|
BYTE
|
无符号 8 位整数
|
BOOLEAN
|
无符号 8 位整数
|
SHORT
|
16 位整数
|
USHORT
|
无符号 16 位整数
|
WORD
|
无符号 16 位整数
|
INT
|
32 位整数
|
LONG
|
32 位整数
|
BOOL
|
32 位整数
|
UINT
|
32 位无符号整数
|
ULONG
|
32 位无符号整数
|
DWORD
|
32 位无符号整数
|
INT64
|
64 位整数
|
UINT64
|
无符号 64 位整数
|
PTR
|
一般指针 (void *)
|
HWND
|
窗口句柄 (指针)
|
HANDLE
|
句柄 (指针)
|
FLOAT
|
单精度浮点数
|
DOUBLE
|
双精度浮点数
|
INT_PTR, LONG_PTR, LRESULT, LPARAM
|
当运行在 x86 或 x64 版本的 AutoIt 时, 一个大到足以容纳一个指针的整数.
|
UINT_PTR, ULONG_PTR, DWORD_PTR, WPARAM
|
当运行在 x86 或 x6 4版本的 AutoIt 时, 大到足以容纳一个指针的无符号整数.
|
STR
|
ANSI 字符串 (至少分配 65536 个字符).
|
WSTR
|
Unicode 宽字符字符串 (至少分配 65536 个字符).
|
STRUCT
|
用于 DllStructCreate() 创建结构
|
*
|
添加 * 到类型的末尾作为另一种类型传递的参考. 例如 "int*" 传递 "int" 类型的指针.
|
Windows API 类型转换为 AutoIt 类型:
WINDOWS API 类型
|
AutoIt 类型
|
LPCSTR/LPSTR
|
STR
|
LPCWSTR/LPWSTR
|
WSTR
|
LPVOID
|
PTR
|
LPxyz
|
xyz*
|
HINSTANCE
|
HANDLE
|
HRESULT
|
LONG
|
LONGLONG/LARGE_INTEGER
|
INT64
|
ULONGLONG/ULARGE_INTEGER
|
UINT64
|
SIZE_T
|
ULONG_PTR
|
要在结构内部使用嵌套结构, 你必须重新定义嵌套结构.
例如, 结构中含有 2 点结构 ("long;long") 将被宣布为 "long;long;long;long".
前两个长值对应第一点结构, 后两个值对应第二点结构.
其它 Windows API 类型见 MSDN.
返回值
成功:
|
返回一个数组, 见备注.
|
失败:
|
@error 设置 为非 0 值.
|
@error:
|
2 = 未知的"返回类型",
4 = 参数个数错误.
5 = 参数错误
|
备注
By default, AutoIt uses the 'stdcall' calling method. To use the 'cdecl' method place ':cdecl' after the return type.
If the function call fails then the @error flag is set to non-zero.
Otherwise an array is returned that contains the function return value and a copy of all the parameters (including parameters that the function may have modified when passed by reference).
$return[0] = function return value
$return[1] = param1
$return[2] = param2
...
$return[n] = paramn
特别提示:这是一项高级功能。错误使用此功能可能会导致AutoIt崩溃。在使用此函数之前,请确保DllCall()不会执行您所需的操作。
相关
DllCall, DllCallbackFree, DllCallbackGetPtr, DllCallbackRegister, DllClose, DllOpen, DllStructCreate, DllStructGetPtr
函数示例
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>
Example()
Func Example()
; Enable GUI event mode.
Opt("GUIOnEventMode", 1)
; Create a simple GUI.
Local $hWnd = GUICreate("DllCallAddress Example")
; Register the close event handler.
GUISetOnEvent($GUI_EVENT_CLOSE, "OnClose")
; Show the GUI.
GUISetState(@SW_SHOWNORMAL, $hWnd)
; Get a pointer to the window's WindowProc().
Local $pWndProc = _WinAPI_GetWindowLong($hWnd, $GWL_WNDPROC)
; Tell the user what is about to happen.
MsgBox($MB_SYSTEMMODAL, "DllCallAddress Example Msg", "When you press OK the test window will close.")
; Explicitly generate a WM_CLOSE event and pass it directly to the WindowProc().
; This should never be done in a real application (Use _SendMessage() instead) but
; it demonstrates how to use the function.
DllCallAddress("LRESULT", $pWndProc, "HWND", $hWnd, "UINT", $WM_CLOSE, "WPARAM", 0, "LPARAM", 0)
EndFunc ;==>Example
Func OnClose()
GUIDelete(@GUI_WinHandle)
MsgBox($MB_SYSTEMMODAL, "DllCallAddress Example Msg", "Close event received, the test window should now be closed.")
EndFunc ;==>OnClose
----------------------------------------
|