This section contains the module-definition file for a minimum dynamic-link library. This file provides input to LINK to define various attributes of the library. Note that there is no STACKSIZE statement, because dynamic-link libraries make use of the calling application's stack.
LIBRARY MinDLL
DESCRIPTION 'MinDLL -- Minimum Code Required for DLL.'
EXETYPE WINDOWS
STUB 'WINSTUB.EXE'
CODE MOVEABLE DISCARDABLE
DATA MOVEABLE SINGLE
HEAPSIZE 0
EXPORTS
MinRoutine @1
WEP @2 RESIDENTNAME
The LIBRARY keyword identifies this module as a dynamic-link library. 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 dynamic-link library.
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 dynamic-link library.
The STUB statement defines an MS-DOS 2.x application that is copied into the body of the library's .DLL file. The purpose of the stub is to provide information to users who attempt to run Windows modules from the MS-DOS command prompt. If you do not provide a STUB statement, the linker inserts one automatically.
The CODE statement defines the default memory attributes of the library's code segments. Movable and discardable code segments offer the most freedom to the Windows memory manager, which ensures that the proper code segment is available when it is needed. You can also use the SEGMENTS statement, which is not included in this example, to define the attributes for individual code segments.
The DATA statement is required. It defines memory attributes of the library's data segment. The MOVEABLE keyword allows the memory manager to move the segment if needed. The SINGLE keyword is required for dynamic-link libraries, because they always have a single data segment, regardless of the number of applications that access it.
The HEAPSIZE statement defines the initial (and minimum) size of a library's local heap. Libraries that allocate local memory (by using the LocalAlloc function) must initialize the heap at library startup time. The heap size is passed to the library's LibEntry routine, which, in turn, can call the LocalInit function to initialize the library's local heap, using that heap size. For more information, see Section 20.3.1.1, “Initializing a Dynamic-Link Library.” In the example, the heap size is set to zero because the local heap is not used.
The EXPORTS statement defines the functions that will be used as entry points from applications or from other dynamic-link libraries. Windows uses this information to establish the proper data segment to be used by each library function. Each function should have a unique 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.