在AutoIt中调用DLL函数,DLLStruct没有数据

Calling DLL function in AutoIt, DLLStruct has no data

本文关键字:DLLStruct 数据 函数 AutoIt 调用 DLL      更新时间:2023-10-16

我是新来的,我会尽力解释我最好的。我正在编写一些信息工具,需要返回与特定硬件 ATM 相关的一些数据,所以我有它的 API,它的文档对 VB6 C++中的代码完全令人困惑所以我需要调用特定的 dll 函数,c++ 中的原始代码是这样的:

typedef struct _wfsversion
{
    WORD            wVersion;
    WORD            wLowVersion;
    WORD            wHighVersion;
    CHAR            szDescription[WFSDDESCRIPTION_LEN+1];
    CHAR            szSystemStatus[WFSDSYSSTATUS_LEN+1];
} WFSVERSION, * LPWFSVERSION;
//and  Function calls APi and expect some  response.
BOOL Wfs_StartUp(void)
{
    WFSVERSION WfsVersion;
    return (WFSStartUp(RECOGNISED_VERSIONS, &WfsVersion) == WFS_SUCCESS);
#define RECOGNISED_VERSIONS 0X00030203

在AutoIt中,我做了以下操作:

#include <WinAPI.au3>
#include <GUIConstantsEx.au3>
#include <Constants.au3>
#include <Array.au3>
Global Const  $hXFSDLL = DllOpen ( "C:Codinginfotoolmsxfs.dll")
Global Const $RECOGNISED_VERSIONS = "0X00030203"
Global Const $lpWFSVersion = "word wVersion;word wLowVersion;word wHighVersion;char szDescription[WFSDDESCRIPTION_LEN+1];char szSystemStatus[WFSSYSSTATUS_LEN+1]"
$structLPWFSVERSION = DllStructCreate($lpWFSVersion)
DllCall($hXFSDLL,"BOOL","WFSStartUp","dword",$RECOGNISED_VERSIONS, "struct", DllStructGetPtr($structLPWFSVERSION))
ConsoleWrite("wVersion = "&DllstructGetData($structLPWFSVERSION,"wVersion"))
ConsoleWrite(@CRLF)
ConsoleWrite("wLowVersion = "&DllstructGetData($structLPWFSVERSION,"wLowVersion"))
ConsoleWrite(@CRLF)
ConsoleWrite("wHighVersion = "&DllstructGetData($structLPWFSVERSION,"wHighVersion"))
ConsoleWrite(@CRLF)
ConsoleWrite("szDescription = "&DllstructGetData($structLPWFSVERSION,"szDescription"))
ConsoleWrite(@CRLF)
ConsoleWrite("szSystemStatus = "&DllstructGetData($structLPWFSVERSION,"szSystemStatus"))
ConsoleWrite(@CRLF)

作为回应,我没有得到任何数据:

wVersion = 0
wLowVersion = 0
wHighVersion = 0
szDescription = 0
szSystemStatus = 0

所以我想知道我做错了什么?

除了 mrt 评论的内容之外,我认为您的函数描述是错误的。 WFSStartUp想要结构指针而不是结构,所以类型应该是struct*而不是struct

Local $ret = DllCall($hXFSDLL, "LONG:cdecl", "WFSStartUp", "dword", $RECOGNISED_VERSIONS, "struct*", DllStructGetPtr($structLPWFSVERSION))

编辑:
我更改了上面的签名以反映msxfs.dll没有使用 stdcall 调用约定的事实,而是cdecl因为这是 AutoIt 文档DllCall所说的关于调用约定的内容:

默认情况下,AutoIt 使用"stdcall"调用方法。要使用"cdecl"方法,请在返回类型后放置":cdecl"。

我引用的DllCall文档可以在这里找到:
https://www.autoitscript.com/autoit3/docs/functions/DllCall.htm