The understanding and function of __stdcall

Source: Internet
Author: User

In a system integration project, encountered a typedef int (__stdcall *func_*****_system_version) (), such a statement, the first contact with _stacall, so the collation is as follows:

Reprint: http://blog.csdn.net/u4110122855/article/details/8266725

Not all languages support _cdcel call rules, but all support _sdtcall call rules, if you use VC to do a DLL, export some functions, if you want this DLL by other languages can also call, VB. Dephi. PB.. Your calling convention as the __stdcallwindows API is _stdcall calling rules,

The function call convention determines how a program implements a function call and how arguments are passed. In a single language program, the calling convention is almost always correct because there is always a default convention for all modules and the header file is responsible for the consistency between the invocation and the invoked program. In a mixed-language program, different languages cannot share the same header file. Errors resulting from the calling convention cannot be discovered at compile time until the program is implemented at run time (run-time) to implement a function call and will immediately cause the application to crash.

Key stack's maintainer parameter pass
__cdecl caller parameter reverse sequence into stack (right-> left)
__stdcall The callee parameter back into the stack (right-> left)
__fastcall the caller parameter to the register, and then into the stack
The thiscall (not the keyword) is called into the stack by the caller parameter, this pointer is stored ECX

In C + +, you can specify the calling convention with the keyword __stdcall when the function is declared or defined. __stdcall calling conventions are often used in Windows programs or API functions. In GUI programs, PASCAL, WINAPI, and callback are all defined as __stdcall. The default calling convention for the C language is __cdecl.

__stdcall's name modification is to underline the first sign (_) and then add the "@" and function parameter bytes (required stack space)

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.