call C++ DLL from VBA

B

Bill Grigg

All,

I have finally (once again) managed to call a DLL from VBA. However, the
only way I could get it to work was by building the DLL with the calling
convention "__stdcall". I would like to use the "__cdecl" calling convention
because the DLL is also called from Matlab. Does anyone know what to do? I am
stuck getting the error message:

Number 49:
Description: Bad DLL calling convention

TIA,

Bill
 
J

Joel

You probably need two entry points into your dll. One for matlab and one for
VBA. Put two subroutines into you DLL with different mames. Then have one
routine call the other routine. That is exactly why the library definition
statment in VBa has an Alias

Public Declare Function FtpOpenFile Lib "wininet.dll" Alias "FtpOpenFileA" _
(ByVal hFtpSession As Long, ByVal sBuff As String, ByVal Access As Long,
ByVal Flags As Long, ByVal Context As Long) As Long

The Alias is the real routine that gets called internal in the DLL. For
example if you wanted to build a DLL that worked with both winXP and Vista.
WindXP is 32 bits and vista is 64 bits. So you would need some modification
in the code to compensate for the difference in the data sizes.

In your case the __cdecl indicates it is using C language calling convention
and __stdcall uses standard calling convention.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top