### Example of a DLL Module Definition File

The module definition file shown here illustrates the most common statements used in a module definition file to build DLLs.

    LIBRARY SAMPLE03 INITINSTANCE TERMINSTANCE

    DATA NONSHARED READWRITE

    EXPORTS

    	nSize ; array size

    	pArray ; pointer to base of array of ints

    	nSwaps ; number of swaps required to sort the array

    	nCompares ; number of comparisons required to sort the array

    	list ; array listing function

    	bubble ; bubble sort function

    	insertion ; insertion sort function

Note: In this module definition file, the `EXPORTS` statement does not include the `selection` function because the source code contains a #pragma export statement for `selection`.

The module statements specified in the module definition file are as follows:

`LIBRARY SAMPLE03 INITINSTANCE TERMINSTANCE`
  This statement identifies the executable file as a dynamic link library and specifies that `SAMPLE03` is the name of the DLL. It also uses the following attributes to specify when the `_DLL_InitTerm` function will be called:
  `INITINSTANCE`
    The function is called the first time the DLL is loaded for each process that accesses the DLL. The alternative is `INITGLOBAL`; the function is called only the first time the DLL is loaded.

    `INITGLOBAL` is the default.

  `TERMINSTANCE`
    The function is called the last time the DLL is freed for each process that accesses the DLL. The alternative is `TERMGLOBAL`; the function is called only the final time the DLL is freed.

    `TERMGLOBAL` is the default.

  `NONSHARED`
    Specifies that the data segment cannot be shared and must be loaded separately for each process. The alternative is `SHARED`; one copy of the segment is loaded and shared by all processes that access the module.

    Note that if you use the `READONLY` attribute, data segments are always shared.

    Note: If the two above data segment attributes conflict, such as `NONSHARED` or `SHARED`, the behaviour is undefined.

  `READWRITE`
    Means that you can read from or write to the data segment. The alternative is `READONLY`; you can only read from the data segment.

    `READWRITE` is the default.

`CODE`
  This statement defines the default attributes for code segments within the DLL. `LOADONCALL` means that the code segment is loaded when it is first accessed. `LOADONCALL` is the default.

  Note: You can also specify `PRELOAD`, but Version 2.0 and later of the OS/2 operating system ignore the `PRELOAD` attribute and use the `LOADONCALL` instead.

`EXPORTS` export
  This statement defines the names of the functions and variables to be exported to other runtime modules. Following the `EXPORTS` keyword are the export definitions, which are simply the names of the functions and variables that you want to export. Each name must be entered on a separate line.

Note:

> When you build your DLL using /Gd-, so that it is statically linked to the runtime library, you must specify the following attributes in your module definition file:

> - INITINSTANCE
> - TERMINSTANCE
> - DATA NONSHARED

Define Code and Data Segments in a DLL

Summary of Module Definition Statements