The call Convention (callingconvention) determines the sequence of the function parameters in which the caller or the caller pushes the parameter to the stack and generates the function modifier name. MFC supports the following call conventions:
1. _ cdecl
The parameter is pushed from right to left to the stack. The caller pushes the parameter to the stack. For a "C" function or variable, the modifier name is underlined before the function name. The "C ++" function is different.
For example, the modified name of the voidtest (void) function is _ test. For a global function that does not belong to a class, what is the modified name? Test @ zaxxz.
This is the default MFC call convention. Because the caller is responsible for popping up the parameter stack, you can define a variable number of parameters for the function, such as the printf function.
2. _ stdcall
The parameter is pushed from right to left to the stack. The parameter is pushed to the stack by the caller. For a "C" function or variable, the modifier name is prefixed with the following line, followed by the function name, followed by the symbol "@" and the number of bytes of the parameter, such as the intfunc (INTA, doubleb) function) the modifier name of is _ FUNC @ 12. The "C ++" function is different. All WIN32API functions follow this convention.
3. _ fastcall
The first two DWORD types or parameters that occupy less bytes are put into the ECX and EDX registers, and the remaining parameters are pushed to the stack in the order from right to left. The called calls bring up the parameter stack. For "C" functions or variables, the modifier name is prefixed with "@" and then the function name, the symbol "@" and the number of bytes of the parameter are followed. For example, the modifier of intfunc (INTA, doubleb) is @ func @ 12. The "C ++" function is different.
Note:
_ Cdecl is C/C ++ and MFCProgramYou can also add the _ cdecl keyword when declaring a function by default. When _ cdecl is used, function parameters are pushed to the stack in the order from right to left, and the caller pops up the parameter stack to clear the stack. Therefore, a function that implements variable parameters can only use this call convention. Every function using the _ cdecl Convention must containCodeTherefore, the size of the executable files generated is relatively large. _ Cdecl can be written as _ cdecl.
_ Stdcall is used to call Win32 API functions. When _ stdcal is used, function parameters are written to the stack in the order from right to left. The called function clears the stack of the transfer parameter before returning, and the number of function parameters is fixed. Because the function body knows the number of passed parameters, the called function can directly clear the stack of the passed parameters with a RET n command before returning the result. _ Stdcall can be written as _ stdcall.
_ Fastcall conventions are used in scenarios with high performance requirements. _ Fastcall: The two DWORD parameters starting from the left of the function are placed in the ECX and EDX registers respectively, the other parameters are still transmitted from the right to the left pressure stack. The called function clears the stack of the transfer parameter before returning. _ Fastcall can be written as _ fastcall.