ThisCall applies only to "C + +" member functions (the this pointer is stored in the CX register, with parameters from right to left)

Source: Internet
Author: User

  1. _stdcall is the default invocation of the Pascal program, and is typically used in the Win32 API, where the function uses a right-to-left stack and empties itself on exit. After the VC compiles the function, it adds an underscore prefix to the function name, followed by the function name with the "@" and the number of bytes of the parameter . The format is :[email protected].
  2. The c calling convention (that is, using the __CDECL keyword description) presses the parameter in the right-to-left order into the stack, and the caller pops up the stack of arguments. The memory stack for routing parameters is maintained by the caller (because of this, the function that implements the mutable argument can only use the calling convention). In addition, there are differences in function name adornment conventions.

    _cdecl are the default calling methods for C and C + + programs . Each function that calls it contains the code that empties the stack, so the resulting executable file size is larger than the call to the _stdcall function. When a VC compiles a function, it will precede the function name with an underscore prefix. It is also the default calling convention for MFC. The format is _functionname.
  3. The __fastcall calling convention is "human" as its name, and its main feature is fast , because it transmits parameters through registers (in fact, it transmits the first two double words (DWORD) or smaller parameters with ECX and edx, the remaining parameters are still transferred from right to left, The called function cleans the memory stack of the routing parameters before returning, and it differs from the previous two in terms of the function name adornment convention.

    The function of the _fastcall method takes the register pass parameter, the VC compiles the function to precede the function name with the "@" prefix, after the function name adds "@" and the parameter the number of bytes. The format is @[email protected].
  4. ThisCall is only applied to the "C + +" member function. This pointer is stored in the CX register and the parameters are pressed from right to left. ThisCall is not a keyword and therefore cannot be specified by the programmer.
  5. Naked call uses the 1-4 calling convention, if necessary, the compiler generates code to hold the ESI,EDI,EBX,EBP register when it enters the function, and the Exit function generates code to recover the contents of those registers. Naked call does not produce such a code. Naked call is not a type modifier and must be used in conjunction with _DECLSPEC.

The keywords __stdcall, __cdecl , and __fastcall can be added directly before the function to be exported, or in the compilation environment setting.../c/c++/ The Code generation option. When the keyword before the output function is different from the selection in the compilation environment, the keyword directly before the output function is valid. Their corresponding command-line arguments are/gz,/gd, and/gr, respectively. The default state is/GD, which is __cdecl.

To completely imitate the Pascal calling convention, you must first use the __stdcall calling convention, and as for the function name decoration conventions, you can imitate them by other means. Also worth mentioning is the WINAPI macro, which Windows.h supports the macro, which translates the function into the appropriate calling convention, which is defined as __stdcall in WIN32. Use the WINAPI macro to create your own APIs.

http://www.jiancool.com/article/5843998959/

ThisCall applies only to "C + +" member functions (the this pointer is stored in the CX register, with parameters from right to left)

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.