__stdcall, __cdecl, CALLBACK, WINAPI Differences

Source: Internet
Author: User

Scenario One: First look at the use of Windows under development:

LRESULT CALLBACK    WndProc (HWND, UINT, WPARAM, LPARAM);
Here is a callback, go to the definition look at
#elif (_msc_ver >= 800) | | Defined (_stdcall_supported) #define CALLBACK    __stdcall#define WINAPI      __stdcall ...

From the above can also be seen under the Windows platform WINAPI and Callbcak is actually consistent;

Scenario Two: In addition we know that when using the DUMPBIN DLL symbol name, assuming that there is an add function, output will be like [email protected]@[email protected], if you add the extern "C" characters, The function symbol of the output is the name of the previously defined add function, which involves the function call problem, because different languages and compiler platform, the Convention is not the same, for example, the function of the formal parameters, the default is pressed into the stack, some from left to right press, some from the right to the left, the different standards are not the same, So if there is an error in the invocation, you must indicate which method is called so that the compiler can recognize it correctly.

So what's the difference between them?

1) First of all, the C call standard is __cdecl, the use of the stack order, ...

While Delphi is using the Pascal call Standard, that is, the standard contract stdcall, is also the default use of Windows Convention, that is, under the Windows platform WINAPI, Callbcak, stdcall is in fact consistent

2) __stdcall and __cdecl are two different calling conventions that define the order in which the function parameters are stacked, whether the call function or the called function pops up the stack, and the method that produces the function decorated name

3) in Windows programs, the callback function must follow the __stdcall calling convention, so the use of callback, of course, can also be directly used __stdcall, mainly to facilitate the separation

Note: About the stacking order, remember the front in the book on the embedded aspects of the order of the press in the stack, mainly they use the assembly, the specific parameters must be pressed into the relevant registers, and then refer to the time can be corresponding, look back, and then do in-depth explanation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.