Function Name modification conventions during C ++ compilation and methods for exporting functions in DLL

Source: Internet
Author: User
Rules for modifying function names during C ++ Compilation:
_ Stdcall call conventions:
1. Take "? "Mark the start of the function name, followed by the function name;
2. The parameter table starts with "@ YG" after the function name, followed by the parameter table;
3. The parameter table is represented in code:
X -- void,
D -- char,
E -- unsigned char,
F -- short,
H -- int,
I -- unsigned int,
J -- long,
K -- unsigned long,
M -- float,
N -- double,
_ N -- bool,
....
Pa -- indicates the pointer. The code behind the pointer indicates the pointer type. If a pointer of the same type appears consecutively, it is replaced by "0". A "0" indicates a repetition;
4. the first item of the parameter table is the type of the return value of the function, followed by the Data Type of the parameter. the pointer ID is prior to the Data Type indicated by the parameter;
5. mark the end of the entire name with "@ Z" after the parameter table. If this function has no parameter, it ends with "Z.
The format is "? Functionname @ YG ***** @ Z "or "? Functionname @ YG * xz ", for example
Int test1 (char * var1, unsigned long) ----- "? Test1 @ yghpadk @ Z"
Void Test2 () ----- "? Test2 @ ygxxz"

_ Cdecl:
The rules are the same as the _ stdcall call Convention above, except that the start mark of the parameter table is changed from "@ YG" to "@ ya ".
_ Fastcall:
The rules are the same as the _ stdcall call Convention above, except that the start identifier of the parameter table changes from "@ YG" to "@ Yi ".

DLL function export Method
There are three methods to export a function from a DLL:
1. Use the def file. It is a text file that contains statements describing different attribute modules of the dynamic link library. If the _ declspec (dllexport) keyword is not used in the program to output the DLL function, there must be a Def file.
Def files generally contain the following statements:
Name: name of the main output program or dynamic link library
Library: This statement specifies the internal name of the dynamic link library, but the connector generates the dynamic link library.
Description: describes the usage of the DLL, which is enclosed in single or double quotation marks.
Stacksize: set the size of the stack in bytes.
Sections: sets the segment attribute.
Exports: lists the DLL export function name and other information.
Version: indicates the dll version.
For the mfc dll created using Appwizard, Appwizard will create a Def file framework, automatically add it to the project, and then add the function for output in the def file. If you are creating a non-mfc dll, you must create your own def file and add it to the project total.
When a DLL is created, the connector uses the def file to create an output exp file and an input library Lib. Then, the connector uses these output files to create a dynamic link library file, the DLL file can be used by connecting to the Lib file displayed by the executable program of the dynamic link library.
2 use the _ declspec (dllexport) keyword
You can use the _ declspec (dllexport) keyword to output functions, Data, classes, or class members from the dynamic link library. If you use this keyword, the def file is no longer used.
To output a function from a dynamic link library, the _ declspec (dllexport) keyword must be placed before the output variable. When a new dynamic link library file is created, generally, a header file containing the original form or function class of the output function is created, and the _ declspec (dllexport) keyword is added to the header file. When the output function of the above dynamic link library is used, you can use the _ declspec (dllimport) keyword to declare the DLL output functions used, and then you can directly use these functions.
3 For the MFC extension function, it uses the afx_ext_class macro to export the class.
The MFC extension DLL uses the afx_ext_class macro output class, and the application that uses the extension DLL also uses this macro input class.

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.