Analysis on function calling methods for Library File Export

Source: Internet
Author: User
Due to work requirements, I encountered a problem of database API encapsulation and calling, which involved the function calling method. Refer to the resources collected on the Internet for sorting and learning. Function calling methods include: 1. _ cdecl is short for c Declaration, indicating the default function calling method in C language: all function parameters are pushed to the stack from right to left. These parameters are cleared by the caller, which is called manual stack clearing. The called function does not require the caller to pass many parameters. Too many or too few parameters are passed by the caller, and even different parameters do not produce compilation errors. 2. _ stdcall is the abbreviation of standardcall, which is the standard call method of c ++. All parameters are pushed to the stack from right to left. If they are call class members, the last inbound pointer is the this pointer. The parameters in the stack are cleared after the called function returns. The command is retnx, and X indicates the number of bytes occupied by the parameter, the CPU automatically pops up X bytes of stack space after ret, which is called automatic stack clearing. During compilation, the function must determine the number of parameters, and the caller must strictly control the generation of parameters. There must be no more or fewer parameters. Otherwise, an error will occur after the return. 3. Pascal is a function call method in PASCAL language and can also be used in C/C ++. The parameter pressure stack sequence is opposite to that of the first two. The return method is the same as _ stdcall. 4. _ fastcall is a quick call method specified by the compiler. Because most function parameters are few, it is time-consuming to use stack transfer. Therefore, _ fastcall usually specifies that the first two (or several) parameters are passed by the register, and the other parameters are passed through the stack. The return method is equivalent to _ stdcall. 5. _ thiscall is specified to solve this pointer passing in class member calls. _ Thiscall requires that this pointer be placed in a specific register, which is determined by the compiler. VC uses ECx and Borland's c ++ compiler uses eax. The return method is equivalent to _ stdcall. The registers involved in _ fastcall and _ thiscall are determined by the compiler. Therefore, they cannot be used as cross-compiler interfaces. Therefore, the COM object interface on Windows is defined as the _ stdcall call method. C does not indicate that the default function is the _ cdecl method (this method can only be used in c). c ++ is the same, but the default call method can be set in the IDE environment. A function with variable parameters must only use the _ cdecl method. For example, the following function: int printf (char * fmtstr ,...); int scanf (char * fmtstr ,...);

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.