How to Call C Functions That Use the _cdecl Calling ConventionLast reviewed: July 16, 1996Article ID: Q153586 |
The information in this article applies to:
SUMMARYIt 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 4.0 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 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.
MORE INFORMATIONIf it is necessary to call functions that use the _cdecl calling convention (such as the MSTEST DLLs), wrap the _cdecl call inside a _stdcall call that is exposed or exported to Visual Basic. This is demonstrated in the following step-by-step example.
Step-by-Step Example
|
Additional reference words: 4.00 vb4win vb432 cdecl
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |