I am new here and I will try to explain my best. I am writing some Info tool that needs to return some data on specific hardware ATM related, so I have its API and it's documentation is totally confusing to code in VB6 C++ so I need to call specific dll function that original code in c++ was like this:
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
In AutoIt I did the following:
#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)
and as response I get no data:
wVersion = 0
wLowVersion = 0
wHighVersion = 0
szDescription = 0
szSystemStatus = 0
so I wonder what am I doing wrong?
Besides what mrt commented I think your function description is wrong.
WFSStartUp
wants struct pointer not a struct so the type should be struct*
not struct
.
Local $ret = DllCall($hXFSDLL, "LONG:cdecl", "WFSStartUp", "dword", $RECOGNISED_VERSIONS, "struct*", DllStructGetPtr($structLPWFSVERSION))
EDIT:
I changed the above signature to reflect the fact that msxfs.dll
is NOT using stdcall calling convention but cdecl
as this is what AutoIt documentation for DllCall
say about calling conventions:
By default, AutoIt uses the 'stdcall' calling method. To use the 'cdecl' method place ':cdecl' after the return type.
The DllCall
documentation I quoted can be found here:
https://www.autoitscript.com/autoit3/docs/functions/DllCall.htm
User contributions licensed under CC BY-SA 3.0