_ Stdcall conventions

Source: Internet
Author: User

_ Stdcall conventions

If a DLL written in VC ++ is to be called by a program written in other languages, the function call method should be declared as _ stdcall. winapi adopts this method, the default call method of C/C ++ is _ cdecl. The _ stdcall method is different from the _ cdecl method for generating symbols for function names. If the C compilation method is used (the function must be declared as extern "C" in C ++), __stdcall indicates that the name of the output function must be underlined, the symbol "@" is followed by the number of bytes of the parameter, in the form of _ functionname @ number. The call Convention of _ cdecl is to only underline the name of the output function, in the form of _ functionname.

In Windows programming, macros of common function types are related to _ stdcall and _ cdecl (Excerpted from windef. h ):

# Define callback _ stdcall // This is the legendary callback function.

# Define winapi _ stdcall // This is the legendary winapi

# Define winapiv _ cdecl

# Define apientry winapi // The dllmain entry is here

# Define apiprivate _ stdcall

# Define Pascal _ stdcall

In Lib. H, the Add function should be declared as follows:

Int _ stdcall add (int x, int y );

In the Application project, the function pointer type should be defined:

Typedef int (_ stdcall * lpaddfun) (INT, INT );

In Lib. h declares the function as _ stdcall, while typedef int (* lpaddfun) (INT, INT) is still used in the application project. An error will occur during runtime (because the type does not match, in the Application project, it is still the default _ cdecl call). The Dialog Box 7 is displayed.

Figure 7 running errors when the call conventions do not match

The section in Figure 8 actually shows the cause of the error, that is, "this is usually a result ...".

Http://pcedu.pconline.com.cn/empolder/gj/vc/0509/699672_6.html

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.