This section contains the module-definition file for the minimum DLL. This file provides input to the linker to define various attributes of the DLL. Note that there is no STACKSIZE statement, since DLLs make use of the calling application's stack.
LIBRARY MinDLL
DESCRIPTION 'MinDLL — Minimum Code Required for DLL.'
EXETYPE WINDOWS
STUB 'WINSTUB.EXE'
CODE MOVABLE DISCARDABLE
DATA MOVABLE SINGLE
HEAPSIZE 0
EXPORTS
MinRoutine @1
WEP @2 RESIDENTNAME
The LIBRARY keyword identifies this module as a DLL. The name of the library, MinDLL, follows this keyword and must be the same as the name of the library's .DLL file.
The EXETYPE WINDOWS statement is required for every Windows application and DLL.
The DESCRIPTION statement takes a string that can be up to 128 characters in length. It is typically used to hold module description information, and perhaps a copyright notice. This statement is optional in a DLL.
The STUB statement defines a DOS 2.x program that is copied into the body of the library's executable (.DLL) file. The purpose of the stub is to provide information to users who attempt to run Windows modules from the DOS command prompt. If no STUB statement is provided, the linker inserts one automatically.
The CODE statement is used to define the default memory attributes of the library's code segments. Movable and discardable code segments allow the most freedom to the Windows memory manager, which will make sure that the proper code segment is available when it is needed. The SEGMENTS statement, which is not included in this example, can also be used to define the attributes for individual code segments.
The DATA statement is required. It defines memory attributes of the library's data segment. The MOVABLE keyword allows the memory manager to move the segment if needed. The SINGLE keyword is required for DLLs. The reason is that DLLs always have a single data segment, regardless of the number of applications that access it.
The HEAPSIZE statement is used to define the initial (and minimum) size of a DLL's local heap. DLLs that perform local memory allocation (using Local-Alloc) must initialize the heap at library start-up time. The heap size is passed to the DLL's LibMain routine, which, in turn, can call LocalInit to initialize the DLL's local heap using that heap size. For more information, see “Initializing a DLL”. In our example, the heap size is set to zero since the local heap is not used.
The EXPORTS statement defines the routines that will be used as entry points from applications or from other DLLs. This information is used by Windows to establish the proper data segment to be used by each DLL routine. Each routine should have a unqiue ordinal entry value, which in this example is specified after the @ as the value 1. The ordinal entry value is an optimization that allows the dynamic-link mechanism to operate faster and to use less memory.