[<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
Exports and imports
------------------------------------------------------------------------------
To make a function available to other .EXEs or .DLL files, known
collectively as modules, the DLL exports the function in the EXPORTS section
of the module definition file. A function can be exported in one of two
ways, by name or by function number, known as an ordinal number. These
alternatives are discussed in more detail in the section entitled 'Coding
for DLLs' below.
For a module to use a function contained in another module, it imports the
function to create a dynamic link to the code for that function, either by
name or by ordinal number. There are two ways to import a function into a
module:
. By linking the module with an import library which contains
information for that function.
. By listing the individual function in the IMPORTS section of the
module definition file.
For example, when linking applications for Windows with the normal language
run time libraries, it is also necessary to link with the library LIBW.LIB
(MS Visual C++) or IMPORTS.LIB (Borland C++), which contain definitions of
all the Windows API functions. These are a special kind of library, called
an import library, which allow the linker to resolve references (calls) to
functions which reside in DLLs. In this case, these are references to
Windows application programming interface (API) functions in the system
DLLs, such as USER, KERNEL and GDI.
When a program refers to a function defined in an import library, the linker
includes the name of the library and a reference to the individual function
in the header of the EXE file. When the application is loaded, these
references are then resolved to the appropriate functions in the appropriate
DLLs.
Only functions which are explicitly called from another module need to be
exported from the DLL and imported to the module. There is no need to export
functions which are only used internally to the DLL itself.
Import libraries are created by an import librarian such as BLILIB.EXE which
is supplied with Blinker, or IMPLIB.EXE which is supplied with Microsoft
Visual C++. For details on using BLILIB, please see the section entitled
'The BLILIB import librarian' later in this chapter.
Online resources provided by: http://www.ClipX.Net --- NG 2 HTML conversion by Dave Pearson