How To Call C Functions That Use the _cdecl Calling Convention (153586)
The information in this article applies to:
- Microsoft Visual Basic Learning Edition for Windows 5.0
- Microsoft Visual Basic Learning Edition for Windows 6.0
- Microsoft Visual Basic Professional Edition for Windows 5.0
- Microsoft Visual Basic Professional Edition for Windows 6.0
- Microsoft Visual Basic Enterprise Edition for Windows 5.0
- Microsoft Visual Basic Enterprise Edition for Windows 6.0
- Microsoft Visual Basic Standard Edition, 32-bit, for Windows 4.0
- Microsoft Visual Basic Professional Edition, 32-bit, for Windows 4.0
- Microsoft Visual Basic Enterprise Edition, 32-bit, for Windows 4.0
This article was previously published under Q153586 SUMMARY
It is not possible to directly call a C function in a DLL if that function
uses the _cdecl calling convention. This is because Visual Basic uses the
_stdcall calling convention for calling functions. This is a problem
because if _cdecl is used, the calling function is responsible for cleaning
up the stack. However, if _stdcall is used, the called function is
responsible for cleaning up the stack.
NOTE: An .EXE file created in Visual Basic will allow you to call a DLL
function that has been declared with the _cdecl calling convention without
an error. It is only when you try to call such a function when running a
program from the Visual Basic IDE, that Visual Basic generates the
following error:
Run-time Error '49':
Bad DLL Calling Convention
The fact that the EXE version allows you to call such functions has been
confirmed to be a bug by Microsoft. You should not rely on this behavior as
this might change in future versions of Visual Basic.
Modification Type: | Minor | Last Reviewed: | 6/29/2004 |
---|
Keywords: | kbAPI kbhowto KB153586 |
---|
|