Module-Definition File (Windows CE 5.0)

A module-definition (.def) file is a text file that contains statements defining an executable (.exe) file or dynamic-link library (DLL).

Although all executable files can use .def files, they are mainly used by the linker tool to create .exe files and DLL files as one of the final steps in the build process. For more information on the build process, see Build Phases.

The statements in a .def file provide the linker with information about exports, attributes, and other information about the application to be linked.

Most statements appear once in the .def file, and accept one specification of arguments, which follows the statement keyword on the same or subsequent lines.

If you repeat the statement with different arguments later in the file, the later statement overrides the earlier one. Many of these statements have an equivalent LINK command-line option.

The SECTIONS, EXPORTS, and IMPORTS statements can appear more than once in the .def file. Each statement can take multiple specifications, which must be separated by one or more spaces, tabs, or newline characters.

The statement keyword must appear once before the first specification, and it can be repeated before each additional specification.

A semicolon at the beginning of each comment line designates comments in the .def file. A comment cannot share a line with a statement, but it can appear between specifications in a multiline statement, such as SECTIONS and EXPORTS.

If a string argument matches a reserved word, it must be enclosed in double quotation marks.

Numeric arguments are specified in decimal or C-language notation.

For examples of .def files, see the files Kbdjpn1.def, Kbdjpn2.def, Kbdkor.def, and Kbdus.def for Windows CE 4.2 or later, which are in %_WINCEROOT%\Public\Common\Oak\Inc.

NAME

This statement specifies a name for the main output file, and it must precede all other statements.

The statement syntax is as follows:

NAME[application][BASE=address]

In LINK, You can specify an output filename with the Output File Name (/OUT) option and set the base address with the Base Address (/BASE) option.

If both NAME and /OUT are specified, /OUT overrides NAME.

LIBRARY

This statement tells LINK to create a DLL and must precede all statements when used. At the same time, LINK creates an import library, unless an export (.exp) file is used in the build.

The statement syntax is as follows:

LIBRARY [library][BASE=address]

The LIBRARY argument specifies the internal name of the DLL. In LINK, you use the Output File Name (/OUT) option to specify the DLL's output name.

The BASE=address argument sets the base address that the operating system uses to load the DLL. This argument overrides the default DLL location of 0x10000000. For more information about base addresses, see the Base Address (/BASE) option.

In LINK, you can specify a DLL build with the /DLL option, and set the base address with the /BASE option.

DESCRIPTION

This statement writes a string into an .rdata section, and uses the following syntax:

DESCRIPTION "text"

You enclose the specified text in single or double quotation marks. To use a literal quotation mark in the string, enclose the string with the other type of quotation mark.

This functionality differs from the comment that you specify in LINK with the /COMMENT option.

STACKSIZE

This statement sets the size of the stack in bytes. You can set the stack in LINK with the Stack Allocations (/STACK) option.

The statement uses the following syntax:

STACKSIZE reserve[,commit]

The reserve argument specifies the total stack allocation in virtual memory. The default stack size is 1 MB. The linker rounds up the specified value to the nearest 4 bytes.

The commit argument is subject to interpretation by the operating system. For example, in Windows NT, it specifies the amount of physical memory to allocate at a time.

Committed virtual memory causes space to be reserved in the paging file. The higher the value, the more time the application saves when it needs more stack space. However, this increases the memory requirements and possibly the startup time.

SECTIONS

This statement sets attributes for one or more sections in the run-time image. You can use it to override the default attributes for each section type.

The statement uses the following syntax:

SECTIONS definitions

The SEGMENTS keyword is supported as a synonym for SECTIONS.

SECTIONS marks the beginning of a list of section definitions. The SECTIONS keyword can be on the same line as the first definition or on a preceding line, but each definition must be on a separate line.

A .def file can contain one or more SECTIONS statements.

The syntax for a section definition is:

section [CLASS 'classname'] attributes

The section name is case sensitive. The CLASS keyword is supported for compatibility, but is ignored. The attributes are one or more of the following: EXECUTE, READ, SHARED, and WRITE.

In LINK, you can specify section attributes with the /SECTION option.

EXPORT

This statement makes one or more definitions available as exports to other applications.

The statement uses the following syntax:

EXPORTS definitions

This statement makes one or more definitions available as exports to other applications. When LINK builds an application that contains exports, it also creates an import library, unless an .exp file is used in the build.

EXPORTS marks the beginning of a list of export definitions. The EXPORTS keyword can be on the same line as the first definition or on a preceding line, but each definition must be on a separate line. A .def file can contain one or more EXPORTS statements.

An export definition uses the following syntax:

entryname[=internalname] [@ordinal[NONAME]] [DATA] [PRIVATE]

The optional keyword PRIVATE prevents entryname from being placed in the import library that LINK generates. However, it has no effect on the export in the run-time image that LINK also generates.

There are three methods for exporting a definition, listed in recommended order of use:

  1. The __declspec(dllexport) keyword in the source code
  2. An EXPORTS statement in a .def file
  3. An /EXPORT specification in a LINK command

All three methods can be used in the same application.

VERSION

This statement tells LINK to put a number in the header of the .exe file or DLL.

The statement uses the following syntax:

  VERSION 
  major[.minor]

The major and minor arguments are decimal numbers in the range 0 through 65,535. The default setting is 0.0.

In LINK, you can specify a version number with the Version Information (/VERSION) option.

See Also

Build Phases | How-to Topics

Last updated on Thursday, February 02, 2006

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.