Re: StdCall vs. CDecl

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



That's why it's customary to use stdcall for exported DLL functions, just
like the Win32 API does across the board.

So, why is StdCall the default if it's usually incorrect? (I'm going to
guess that it's a COM thing.)

You may want to reread what I wrote. stdcall is the default, cdecl is the odd
one out.

Oh!!! We have a bunch of DLLs that all use CDecl because that's the default
that Visual Studio gives us. We also have a bunch of Ada and FORTRAN code that
calls into those libraries, probably using StdCall semantics (none of our code
in either language uses any keywords to specify the calling convention, so I
would hope that they choose StdCall by default). We're probably leaking some
stack space with each call. I guess I need to go through all of our native
library projects and change them to use StdCall, and do the same with all of our
managed code (all of which, today, explicitly uses CDecl when calling into our
libraries).


.



Relevant Pages

  • Mixed stdcall and cdecl code
    ... I'm writing a DirectShow capture filter, which requires the stdcall calling ... cdecl calling convention, because I was getting "unresolved external symbol" ... or am I likely to have stack problems unless I explicitly declare ...
    (microsoft.public.win32.programmer.directx.video)
  • Mixed stdcall and cdecl code
    ... I'm writing a DirectShow capture filter, which requires the stdcall calling ... cdecl calling convention, because I was getting "unresolved external symbol" ... or am I likely to have stack problems unless I explicitly declare ...
    (microsoft.public.multimedia.directx.dshow.programming)
  • Re: calling convention stdcalll and cdecl call
    ... What you have written is not __stdcall anymore, but your own calling convention that supports a variable number of arguments. ... which does the same job that __cdecl designed to do ... All you know is that compiler pushes parameters right to left and you are responsible to clean the stack. ...
    (microsoft.public.vc.language)
  • Re: StdCall vs. CDecl
    ... Because the worst thing that happens when you call a cdecl function as a stdcall function is that you leave the arguments on the stack after the function returns. ... several different home grown libraries, all of which use CDecl calling semantics. ...
    (microsoft.public.dotnet.framework.interop)
  • Re: Cannot compile sample with VC++ 6 SE
    ... The problem was in wrong calling convention. ... If you change the compiler default to __stdcall, ... are exposed to the opposite type of error when a function requires __cdecl. ...
    (microsoft.public.win32.programmer.ui)