在AutoIt中调用DLL函数,DLLStruct没有数据
Calling DLL function in AutoIt, DLLStruct has no data
我是新来的,我会尽力解释我最好的。我正在编写一些信息工具,需要返回与特定硬件 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
相关文章:
- 防止主数据类型C++的隐式转换
- 用于访问容器<T>数据成员的正确 API
- 嵌套在类中时无法设置成员数据
- 使用流处理接收到的数据
- 静态数据成员的问题-修复链接错误会导致编译器错误
- 处理小于cpu数据总线的数据类型.(c++转换为机器代码)
- 在cuda线程之间共享大量常量数据
- C++将文本文件中的数据读取到结构数组中
- 如何在C++中序列化结构数据
- 在C++中打印指向不同基元数据类型的指针的内存地址
- 通过套接字[TCP]传输数据 如何在C / C ++中打包多个整数并使用send() recv()传输数据
- 在c代码之间共享数据的最佳方式
- 链表,反向函数,数据结构
- 数据成员SFINAE的C++17测试:gcc vs clang
- C++浮点数据类型和字符串数据类型无法子到模板函数中
- 如何对点云数据进行排序
- 从矢量<无符号字符>转换为字符* 包括垃圾数据
- 尝试通过OCI例程从Oracle获取blob数据,但出现错误:ORA-01008:并非所有变量都绑定
- Cuda C++:设备上的Malloc类,并用来自主机的数据填充它
- 在AutoIt中调用DLL函数,DLLStruct没有数据