RAD Studio
|
Import libraries provide access to the functions in a Windows DLL. Import libraries contain records. Each record contains the name of a DLL and specifies where in the DLL the imported functions reside. These records are bound to the application by the linker and provide Windows with the information necessary to resolve DLL function calls. You can substitute an import library for part or all of the IMPORTS section of a module definition file.
IMPDEF takes as input a DLL name, and produces as output a module definition file with an EXPORTS section containing the names of functions exported by the DLL.
IMPDEF <options> <destination.def> <source.dll>
Option |
Description |
-a |
Adds '_' alias for cdecl functions for compatibility with Microsoft libraries |
-h |
Emits hints |
For example:
IMPDEF DestName.DEF SourceName.DLL
To display command line help, enter:
impdef
This creates a module definition file named DestName.DEF from the file SourceName.DLL. The resulting module definition file would look something like this:
LIBRARY <FileName> DESCRIPTION '<Description>' EXPORTS <ExportFuncName> @<Ordinal> . . . <ExportFuncName> @<Ordinal>
IMPDEF is useful for a DLL that uses C++ classes. If you use the __declspec (or _export) keyword when defining a class, all of the non-inline member functions and static data members for that class are exported. It's easier to let IMPDEF make a module definition file for you because it lists all the exported functions, and automatically includes the member functions and static data members.
Since the names of these functions are mangled, it would be tedious to list them all in the EXPORTS section of a module definition file simply to create an import library from the module definition file. If you use IMPDEF to create the module definition file, it will include the ordinal value for each exported function. If the exported name is mangled, IMPDEF will also include that function's unmangled, original name as a comment following the function entry. So, for instance:
LIBRARY <FileName> DESCRIPTION '<Description>' EXPORTS <MangledExportFuncName> @<Ordinal> ; <ExportFuncName> . . . <MangledExportFuncName> @<Ordinal> ; <ExportFuncName>
IMPDEF creates an editable source file that lists all the exported functions in the DLL. You can edit this .DEF file to contain only those functions that you want to make available to a particular application, then run IMPLIB on the edited .DEF file. This results in an import library that contains import information for a specific subset of a DLL's export functions.
Suppose you're distributing a DLL that provides functions to be used by several applications. Every export function in the DLL is defined with __declspec (or _export). Now, if all the applications used all the DLL's exports, then you could use IMPLIB to make one import library for the DLL. You could deliver that import library with the DLL, and it would provide import information for all of the DLL's exports. The import library could be linked to any application, thus eliminating the need for the particular application to list every DLL function it uses in the IMPORTS section of its module definition file.
But suppose you want to give only a few of the DLL's exports to a particular application. Ideally, you want a customized import library to be linked to that application--an import library that provides import information only for the subset of functions that the application will use. All of the other export functions in the DLL will be hidden to that client application.
To create an import library that satisfies these conditions, run IMPDEF on the compiled and linked DLL. IMPDEF produces a module definition file that contains an EXPORT section listing all of the DLL's export functions. You can edit that module definition file, remove the EXPORTS section entries for those functions you don't want in the customized import library, and then run IMPLIB on the module definition file. The result will be an import library that contains import information for only those export functions listed in the EXPORTS section of the module definition file.
Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
|
What do you think about this topic? Send feedback!
|