. Def File

Source: Internet
Author: User

The following is an excerpt from msdn. However, you do not need to define your own def file for programming in VC:

Module definition (. Def) File

The module definition (. Def) file provides the linker with information about the export, attributes, and other aspects of the linked program. When a DLL is generated, the. Def file is the most useful. Because there are Linker options that can be used instead of the module Definition Statement, the. Def file is usually not required. You can also use _ declspec (dllexport) as a method to specify the export function.

In the linker stage, you can use the/DEF (specified module definition file) linker option to call the. Def file.

If the generated. EXE file is not exported, using the. Def file will increase the output file and reduce the loading speed.

Rules of the module-defined statements

The following syntax rules apply to all statements in the. Def file. Other rules applicable to specific statements are described with each statement.

Statements, attribute keywords, and user-specified identifiers are case sensitive.
Long file names that contain spaces or semicolons (;) must be enclosed in quotation marks.
Use one or more spaces, tabs, or line breaks to separate statement keywords from their parameters and statements. The colon (:) or equal sign (=) of the specified parameter has zero or multiple spaces, tabs, or line breaks.
If you use name or library statements, these statements must be before all other statements.
In the. Def file, the sections and exports statements can appear multiple times. Each statement can use multiple specifications. Each specification must be separated by one or more spaces, tabs, or line breaks. The statement keyword must appear before the first criterion and can be repeated before each additional criterion.
Many statements have equivalent link command line options. For more information, see the corresponding link options.
The comment in the. Def file is specified by the semicolon (;) at the beginning of each comment line. A comment cannot share a row with a statement, but it can appear between multiple statement specifications. (Sections and exports are multi-line statements .)
Specify the numeric parameter in decimal or hexadecimal format.
If the string parameter matches the reserved word, the string parameter must be caused by double quotation marks.

Description "text"

This statement writes the string to the. RDATA section. Use single or double quotation marks ('or ") to enclose the specified text. To use quotation marks (single or double quotation marks) in a string, enclose the string with other types of tags.

In the module definition file, description is only valid when the Virtual Device Driver (VxD) is generated.

Exetype: Dynamic | dev386

In the module definition file, exetype is valid only when the Virtual Device Driver (VxD) is generated. If exetype is not specified in the module definition file when a virtual device driver is generated, and the/exetype linker option is not specified, static loading (dev386) takes effect.

Exports
Definitions

The exports statement introduces a section composed of one or more definitions (exported functions or data. Each definition must be on a single row. The exports keyword can be on the same line of the first definition or on the previous line .. The def file can contain one or more exports statements.

The syntax for exporting definitions is:

Entryname [= internalname] [@ ordinal [noname] [private] [Data]
Entryname is the name of the function or variable to be exported. This is required. If the exported name is different from the DLL name, use internalname to specify the name exported in the DLL. For example, if the DLL export function func1 () is used as func2 (), you should specify:

Exports
Func2 = func1
@ Ordinal: Specify the sequence number instead of the function name to enter the DLL export table. This helps minimize the DLL size .. The LIB file will contain the ing between the serial number and the function, which allows you to use the function name as usual in a DLL project.

The optional noname keyword can only be exported by sequence number and reduce the size of the exported table in the result DLL. However, if you want to use getprocaddress on the DLL, you must know the sequence number because the name will be invalid.

The optional private keyword prohibits you from placing entryname in the import/export repository generated by link. It is invalid for exporting images generated by links.

The optional data keyword specifies that the exported data is not the code. For example, you can export data variables as follows:

Exports
I Data
When using private and data for the same export, private must be in front of data.

There are three methods for exporting definitions, which are recommended in sequence:

The _ declspec (dllexport) keyword in the source code
Exports statement in the. Def File
/Export specification in link command
All three methods can be used in the same program. Link also creates Import and Export files when generating programs that contain export, unless the. Exp file is used in the generation.

The following is an example of the exports section:

Exports
Dllcanunloadnow @ 1 private data
Dllwindowname = Name Data
Dllgetclassobject @ 4 noname private
Dllregisterserver @ 7
Dllunregisterserver
Note: when using the. Def file to export a variable from the DLL, you do not need to specify _ declspec (dllexport) on the variable ). However, in any DLL file, _ declspec (dllimport) must still be used in the data declaration ).

Library [library] [base = address]

This statement notifies link to create a DLL. Link also creates a Import/Export Database, unless the. Exp file is used in the generation.

The library parameter specifies the DLL name. You can also use the/out linker option to specify the DLL output name.

The base = address parameter sets the base address used by the operating system to load the DLL. This parameter is used to override the default DLL location of 0x10000000. For more information about the base address, see/base options.

Remember to use the/DLL linker option when generating the DLL.

/Heap: Reserve [, commit]

Heapsize provides the same functions as/heap connector options.

Name [application] [base = address]

This statement specifies the name of the primary output file. Another method to specify the output file name is to use the/out linker option, and another method to set the base address is to use the/base linker option. If both methods are specified,/out overwrites the name.

If a DLL is generated, the name will only affect the DLL name.

Sections
Definitions

The sections statement introduces a section composed of one or more definitions (access instructions for each section of the project output file. Each definition must be on a single row. The sections keyword can be on the same line or the previous line where the first definition is located .. The def file can contain one or more sections statements.

This sections statement sets attributes for one or more sections in the image file and can be used to override the default attributes for each section type.

The format of definitions is:

. Section_name specifier

Here,. section_name is the node name in the program image, and specifier is one or more of the following access modifiers:

Execute
Read
Shared
Write
Separate modifier names with spaces. For example:

Sections
. RDATA read write
The start position of the definitions section list. Each definition must be on a single row. The sections keyword can be on the same line or the previous line where the first definition is located .. The def file can contain one or more sections statements. The segments keyword can be used as a synonym for the sections.

Earlier versions of Visual C ++ support:

Section [class 'classname'] specifier
For compatibility consideration, the class keyword is supported, but it is ignored.

Another way to specify the section attribute is to use the/section option.

Stacksize reserve [, commit]

This statement sets the stack size (in bytes ). Another way to set a stack is to use the stack allocation (/stack) option. For more information about the reserve and commit parameters, see the documentation on this option.

This option is invalid for DLL.

Stub: Filename

When a module definition file is used to generate a Virtual Device Driver (VxD), Stub allows you to specify the image_dos_header structure (in winnt. h) instead of the default header file name.

Another way to specify filename is to use the/stub linker option.

In the module definition file, Stub is valid only when the Virtual Device Driver (VxD) is generated.

Version major [. Minor]

This statement notifies link to put a number in the. exe file or DLL header. The major and minor parameters are decimal numbers from 0 to 65,535. The default value is 0.0.

Another way to specify the version number is to use the version information (/version) option.

VxD filename

Specifies the name of the Virtual Device Driver (VxD. By default, VxD obtains the same name as the first object file.

Another way to specify the virtual device driver version is to use the/VxD linker option, and the other way to name the output file is to use the/out option.

In the module definition file, VxD is valid only when the Virtual Device Driver (VxD) is generated.

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.