Calling DLL function in AutoIt, DLLStruct has no data


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];

//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("wLowVersion = "&DllstructGetData($structLPWFSVERSION,"wLowVersion"))
ConsoleWrite("wHighVersion = "&DllstructGetData($structLPWFSVERSION,"wHighVersion"))
ConsoleWrite("szDescription = "&DllstructGetData($structLPWFSVERSION,"szDescription"))
ConsoleWrite("szSystemStatus = "&DllstructGetData($structLPWFSVERSION,"szSystemStatus"))

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?

asked on Stack Overflow Nov 21, 2014 by Ram Demon • edited Nov 21, 2014 by Andreas

1 Answer


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))

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:

answered on Stack Overflow Nov 21, 2014 by VoltagE-ThE • edited Sep 19, 2015 by rav_kr

User contributions licensed under CC BY-SA 3.0