问题描述
我正在尝试从AutoIt调用GetComputerNameA
,这是我的代码:
Local $mystruct = DllStructCreate(toStr("struct;dword;char[1024];endstruct"))
DllStructSetData($mystruct,1,1024)
Local $result = DllCall("kernel32.dll","int","GetComputerNameA","ptr",DllStructGetPtr($mystruct,2),1))
MsgBox(0,"AutoIt","Success")
但是运行它之后,它什么也不会打印,就像脚本崩溃而没有错误。
知道为什么它无法调用吗?
解决方法
它有两个参数,specifically:
BOOL GetComputerNameA(
LPSTR lpBuffer,LPDWORD nSize
);
第一个是LPSTR
(指向char
数组的指针),第二个是LPDWORD
(指向unsigned int
的指针)。
这是您的称呼方式:
Func _get_computer_name()
Local $dll_struct = DllStructCreate("char[17]")
$sz = DllStructCreate('int')
Local $x = DllCall("kernel32.dll","int","GetComputerNameA","ptr",DllStructGetPtr($dll_struct),"int_ptr",DllStructGetPtr($sz))
Return DllStructGetData($dll_Struct,1)
EndFunc