I'm using Windows 10 (64-bit) and Excel 2016 (32-bit) and want to implement the control of a Yocto-4-20mA-Tx module (https://www.yoctopuce.com/EN/products/usb-actuators/yocto-4-20ma-tx) in VBA.
According to the documentation the DLL is written in C and below are three essential functions.
int yapiInitAPI(int connection_type, char *errmsg);
int yapiUpdateDeviceList(int forceupdate, char *errmsg);
int yapiHTTPRequest(char *device, char *request, char *buffer, int buffsize, int *fullsize, char *errmsg);
I have read (but probably not fully understood) the following:
I try to implement the first function (yapiInitAPI) in a VBA module. With the DLL located in application folder
Option Explicit
Private Declare Function yapiInitAPI Lib "yapi" (ByVal connection_type As Long, ByVal errmsg As String) As Long
Sub myInit()
Dim nReturn As Long
Dim sError As String
nReturn = yapiInitAPI(1, sError)
MsgBox sError
MsgBox nReturn
End Sub
Running this results in
"Run-time error '49': Bad DLL calling convention"
on the yapiInitAPI(1, sError) line.
Here are some questions:
- Can all DLLs be implemented in VBA or do they have to follow a standard?
- I think the "char *errmsg" that I've implemented as "ByVal errmsg As String" is the problem, how should "char *" be translated to in VBA?
- When I download the DLL from yoctopuce I get two versions 32-bit and 64-bit, should I use a specific one. If so, does it depend on my OS or on the Office version?
- I put the DLL in my application folder (i.e. where the .xlsm is stored) and can access it with "Lib 'yapi'" in VBA if I put it in Windows-System32 (and deletes it from application folder) it complains about file not found. Shouldn't this be the same?