Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default call C++ DLL from VBA

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default call C++ DLL from VBA

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.




"Bill Grigg" wrote:

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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Wouldn't know what to call it! 1Fish2Fish Excel Worksheet Functions 5 August 26th 08 07:37 PM
How to call this DLL? Paul Lenz Excel Programming 0 September 9th 07 08:12 PM
Call Center Management: How to calculate 'cost per call' Denniso6 Excel Discussion (Misc queries) 2 June 25th 06 05:01 PM
Run or Call MBlake[_2_] Excel Programming 7 August 27th 05 09:29 PM
call sub Claudia Dell'Era[_2_] Excel Programming 3 October 3rd 03 01:31 PM


All times are GMT +1. The time now is 08:14 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"