__stdcall, __cdecl, CALLBACK, WINAPI Differences

Source: Internet
Author: User

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

Lresult CALLBACK    WndProc (HWND, UINT, WPARAM, LPARAM);
Here's a callback, go to the definition to see
#elif (_msc_ver >= 800) | | Defined (_stdcall_supported)
#define CALLBACK    __stdcall
#define WINAPI      __stdcall
...

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

Scenario Two: In addition, we know that in the use of DUMPBIN DLL symbol name, assuming that there is an add function, the output will be like the add@ @YANHH @z, if you add a character such as extern "C", the output function symbol is the previously defined add function name, This involves the problem of function invocation, because different languages and compiler platforms do not have the same conventions, for example, the function of the formal parameters, the default is to press into the stack, some are from left to right, some are pressed from right to left, different standards are not the same, so if the call will be an error, you must indicate which way to call So that the compiler can recognize it correctly.

So what's the difference between them?

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

And Delphi is the use of Pascal calling Standard, that is, the standard convention stdcall, Windows default is used by the Convention, that is, under the Windows platform WINAPI, Callbcak, stdcall are in fact consistent

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

3 in the Windows program, the callback function must comply with the __stdcall calling convention, so the use of callback, of course, can also directly use __stdcall, mainly to distinguish

Note: about the order into the stack, remember the front in the embedded aspects of the book on the stack in order to explain more, mainly they use the assembly, the specific parameters must be pressed into the register, and then refer to the time can be a 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.