Bad DLL calling convention in my MFC (for VB) DLL 
Author Message
 Bad DLL calling convention in my MFC (for VB) DLL

Forgive me if this is not the forum for this type of question but it
seemed logical. I am writing an extension DLL for Visual Basic using
MSVC 6. I have exported my simple test function and it seems to call and
function perfectly from my VB test application. Unfortunately when the
DLL function returns control to the VB app, it gives me a message that
says 'Bad DLL calling convention.' - which is supposed to mean that the
args do not match...but they do!! Anyone who could give me any
suggestions on this would be greatly appreciated - I am on a deadline!!!

Thanks very much,

Darryl



Sat, 21 Jul 2001 03:00:00 GMT  
 Bad DLL calling convention in my MFC (for VB) DLL

Quote:

>Darryl

 are u using "_stdcall" or " WINAPI " in your C function declarations ?
pls. post some sample code to help exactly know where the problem occurs...

ItheG



Sat, 21 Jul 2001 03:00:00 GMT  
 Bad DLL calling convention in my MFC (for VB) DLL

I too ran into this problem.  After much searching, I discovered that Visual
Basic does not support the '_cdecl' calling convention.  Rather, it requires
you to use the '_stdcall' calling convention.  You can change the default
calling convention (at least in VC++ 6.0) under 'Project...Settings', C/C++
tab, and choose the Code Generation category.  You could also explicitly
putting '_stdcall' in each of your function declarations.  I did not do it
this way, so I am not exactly sure on the syntaxing for that method.

You should also note that the '_stdcall' calling convention uses function
name decoration.  This info on '_stdcall' function name decoration was taken
from the VC++ 6.0 online documentation :

"An underscore (_) is prefixed to the name. The name is followed by the at

Therefore, the function declared as int func( int a, double b ) is decorated

There are a couple of Microsoft Knowledge Base articles that explain C++
DLL's and calling them from VB (and the bad calling convention error) in
quite a bit of detail.  They are :

Article ID: Q153586
Article ID: Q85108

If you are still having troubles, let me know and I'll post the code I used
to implement a DLL in VC++ and the code I used in Visual Basic to call the
DLL.

Hope this helps...

Mark   :-)

Quote:

> Forgive me if this is not the forum for this type of question but it
> seemed logical. I am writing an extension DLL for Visual Basic using
> MSVC 6. I have exported my simple test function and it seems to call and
> function perfectly from my VB test application. Unfortunately when the
> DLL function returns control to the VB app, it gives me a message that
> says 'Bad DLL calling convention.' - which is supposed to mean that the
> args do not match...but they do!! Anyone who could give me any
> suggestions on this would be greatly appreciated - I am on a deadline!!!

> Thanks very much,

> Darryl



Sat, 21 Jul 2001 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. VC6 DLL calls VB6 DLL calls back to VC6 DLL: Occasional GPF or ‘Bad DLL calling convention'

2. Bad DLL calling convention?

3. Bad dll calling convention

4. bad dll calling convention, on conversion from 16bit to 32 bit

5. Bad DLL calling convention?

6. Bad DLL calling convention

7. Bad DLL calling convention

8. Bad DLL Calling Convention

9. DLL and VB -- Bad Calling Convetion

10. MFC DLL needs to be called from Non-MFC VB.

11. Calling an exported function of a dll which are exported Stdcall calling convention

12. HOWTO? Calling VB DLL from C++ DLL

 

 
Powered by phpBB® Forum Software