18.4.1 Writing the Module-Definition File

Summary: A module-definition file is required for DLLs.

The module-definition file is an ASCII text file that lists attributes of a library or application (in the case of an application, this file is optional). The module-definition file gives directions to the linker that supplement the information on the command line.

This module-definition file tells the linker to create a DLL called CSTR.DLL with INITINSTANCE data. The library has exported procedure VioWrtCStr, GetPCount, and GetGCount, and the data segment PRIVDAT is not shared between programs:

LIBRARY CSTR INITINSTANCE

EXPORTS

VioWrtCstr

GetGCount

GetPCount

DATA SINGLE NONSHARED

The LIBRARY statement need not specify a name. If the name is omitted, the linker gives the library the base filename of the module-definition file. The default file extension is .DLL. The INITINSTANCE attribute is optional and is significant only if you have initialization code. If you specify INITINSTANCE, then the library initialization is called each time a new process gains access to the library. Otherwise, it will be called once only.

Summary: At least one procedure must be listed after EXPORTS.

The EXPORTS statement lists identifiers (procedures and variables) that can be accessed directly by client programs. Note that if you give a procedure the EXPORTS attribute from within the source code, you do not need to list the procedure here. The EXPORTS keyword automatically exports the procedure by name, so putting the names of the procedures in the module-definition file is not required. However, exported variables must be listed in a module-definition file.

The DATA statement lists attributes for data segments (DGROUP) in the DLL. The default for DLLs, SINGLE, specifies that one DGROUP is shared by all instances of the DLL. NONSHARED specifies that all other data segments are not to be shared. See Section 13.15, “CODE, DATA, and SEGMENTS Attributes.”