Jump to content

Calling a function method in a dll


Recommended Posts

There is an API for hardware, which is implemented through Lusbapi.dll

In the C ++ reference it looks like this:
1) if (GetDllVersion() != 2) { printf("error 1"); }
2) pModule = static_cast<ILE440 *>(CreateInstance("e440"));
if (pModule == NULL) { printf("error 2"); }
3) if (!pModule->GetModuleName()) { printf("error 3"); }

For AutoIt I rewrote:
$hDLL = DllOpen('Lusbapi.dll')
1) $aRes = DllCall($hDLL, 'LRESULT', 'GetDllVersion')
if $aRes[0] <> 2 then Exit
2) $tDeviceName = DllStructCreate("char DeviceName[9]")
DllStructSetData($tDeviceName, "DeviceName", 'e440')
$aRes = DllCall($hDLL, 'PTR', 'CreateLInstance', 'STRUCT*', $tDeviceName)
$pModule = $aRes[0]
if $pModule == Null then Exit
3) At this step, the error
$aRes = DllCall($hDLL, 'PTR', 'GetModuleName')

The function GetModuleName was not found (since this is a method from the CreateLInstance function), I could not implement a call to the method

Link to comment
Share on other sites

Hello.  this should work.


Local $sDeviceName="e440"
Local $aCall = DllCall($hDLL, 'dword', 'CreateLInstance', 'str', $sDeviceName)


Link to comment
Share on other sites

So part of your include lusbapi.h has some struct constructs where the pointer reference is to the function

extern "C" DWORD WINAPI GetDllVersion(void);
extern "C" LPVOID WINAPI CreateLInstance(PCHAR const DeviceName);


// ==========================================================================
// *************************** L-Card USB BASE ******************************
// ==========================================================================
	virtual BOOL WINAPI OpenLDevice(WORD VirtualSlot) = 0;
	virtual BOOL WINAPI CloseLDevice(void) = 0;
	virtual BOOL WINAPI ReleaseLInstance(void) = 0;
	virtual HANDLE WINAPI GetModuleHandle(void) = 0;
	virtual BOOL WINAPI GetModuleName(PCHAR const ModuleName) = 0;
	virtual BOOL WINAPI GetUsbSpeed(BYTE* const UsbSpeed) = 0;
	virtual BOOL WINAPI LowPowerMode(BOOL LowPowerFlag) = 0;
	virtual BOOL WINAPI GetLastErrorInfo(LAST_ERROR_INFO_LUSBAPI* const LastErrorInfo) = 0;

struct ILE140 : public ILUSBBASE
	virtual BOOL WINAPI GET_ADC_PARS(ADC_PARS_E140* const AdcPars) = 0;
	virtual BOOL WINAPI SET_ADC_PARS(ADC_PARS_E140* const AdcPars) = 0;
	virtual BOOL WINAPI START_ADC(void) = 0;


For that to work you probably need


Link to comment
Share on other sites

You need to do something like this.


Local $tFunctions = DllStructCreate("ptr[" $iNumberOfFunctions "]", $pModule)
DllCallAddress("none", DllStructGetData($tFunctions,1, 4)) ;GetModuleHandle



Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...