【问题标题】:Calling DLL function in AutoIt, DLLStruct has no dataAutoIt中调用DLL函数,DLLStruct没有数据
【发布时间】:2014-11-21 10:08:38
【问题描述】:

我是新来的,我会尽力解释。 我正在编写一些信息工具,它需要返回与特定硬件 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:\Coding\infotool\msxfs.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

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

【问题讨论】:

  • WFSDDESCRIPTION_LEN 和 WFSSYSSTATUS_LEN 的值从何而来?尝试将这 2 个常量替换为适当的整数值并加 1,然后将临时整数放入 lpWFSVersion 字符串中。
  • 确实是错误,我按照 xfsapi.h 中的说明更改为 256+1 :(

标签: c++ autoit cen-xfs


【解决方案1】:

除了 mrt 评论之外,我认为您的功能描述是错误的。 WFSStartUp 想要 struct pointer 而不是 struct 所以类型应该是 struct* 而不是 struct

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

编辑:
我更改了上述签名以反映 msxfs.dll 未使用 stdcall 调用约定但 cdecl 的事实,因为这是 DllCall 的 AutoIt 文档中关于调用约定的内容:

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

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

【讨论】:

  • 它适用于:struct* 或 ptr,我从控制台写入获取值问题现在我无法验证返回码,它为 NULL,我尝试了 Boolean、bool、integer,但当我没有返回任何内容时这样做:$ret=DllCall($hXFSDLL,"BOOL","WFSStartUp","dword",$RECOGNISED_VERSIONS, "struct", DllStructGetPtr($structLPWFSVERSION)) ConsoleWrite("wVersion = "&amp;DllstructGetData($structLPWFSVERSION,"wVersion")) 我更改了 WFSDSCRIPTION 和 WFSSYSSTATUS 的值 WFSstarup 应该返回数值:WFS_SUCCESS (0) WFS_ERR_ALREADY_STARTED (-1) WFS_ERR_API_VER_TOO_HIGH (-2) WFS_ERR_API_VER_TOO_LOW (-3)
猜你喜欢
  • 2013-11-25
  • 2011-03-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多