_ 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