调用GetComputerNameA时,程序崩溃而没有错误

问题描述

我正在尝试从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

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...