Loading color scheme

What is a Module Definition File (.DEF file)?

A module definition DEF file (*. def) is a text file containing one or more module statements describing various attributes of a DLL. The DEF file is especially useful when one needs to disable the name mangling of the exported functions and variables.


At a minimum, the DEF file must contain at least LIBRARY and EXPORTS module definition operators (see below).
The first statement in the file must be LIBRARY. This statement defines the DEF file as belonging to the DLL. The LIBRARY statement is followed by the name of the DLL. The linker puts this name in the DLL import library.
Next going, the EXPORTS statement lists the names and, optionally, ordinal values of functions exported by the DLL. You assign a function with an ordinal number, followed by the function name with an @ sign and a number. When specifying ordinal values, they must be in the range from 1 to N, where N is the number of functions exported by the DLL. If you do not want to assign an ordinal number, you can omit @1...@N numbers. 

For example, a Sample MyLib DLL containing Sample functions might look like this:

LIBRARY MYLIB
EXPORTS
GetVersion
AddSomething
DeleteSomething
ShowMessage

When you use the MFC DLL wizard to create a DLL, the MFC wizard creates a Def file skeleton and automatically adds it to the project. Add the names of the functions to export to this file. For DLLs other than MFC, create a DEF file and add it to the project. Then select Project->Properties -> Linker -> Enter Module Definition File and enter the name of the DEF file. Repeat this step for each configuration and platform, or do it simultaneously by selecting Configuration = All configurations and Platform = All platforms.
When exporting functions to a C++ file, you must either put the internal names in the DEF file or define the exported functions using the standard C layout, using the extern "C" modifier. If you need to put internal names in a DEF file, you can get them using the DUMPBIN tool or using the /MAP parameter of the linker. Note that the internal names generated by the compiler depending on the compiler. If the DEF file contains internal names created by the Microsoft C++ compiler (MSVC), then applications that are associated with the DLL must also be built using the same version of the MSVC compiler, so that the internal names in the calling application match the exported names in the Def file of the DLL.

Source: microsoft

 

Get all interesting articles to your inbox
Please wait