
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