Creating a DLL

To build a DLL from a particular source code module, the code is compiled in a similar manner to that used for any other Presentation Manager application code. However, use of the /Ge- option will cause the C Set/2 compiler to produce a DLL module.

CC /L- /G3 /Ti+ /Gm+ /Ge- MYDLL OS2386.LIB MYDLL.DEF

This command sequence instructs the compiler to take the file MYPROG.C, to compile and link edit it to produce a dynamic link library named MYPROG.DLL, and to use the file named MYPROG.DEF as input to the linking process. Use of the /Gm+ option enables multithreading, and use of the /Ge- option directs C Set/2 to produce a DLL module.

A sample module definition file for use when creating a DLL is shown in Figure "Sample Module Definition File to Create a DLL":

The following rules apply to module definition files when used to create dynamic link libraries:

  • The LIBRARY statement must be used, and the module name declared must be the same as the file name of the DLL. The keywords INITINSTANCE and TERMINSTANCE may be used to indicate that any initialization code should be executed for each process which accesses the DLL.

  • If the DLL will be accessed by separate processes within the system, separate data segments should be created for each process; this is achieved by specifying DATA MULTIPLE in the module definition file

  • The STACKSIZE statement must not be used since a DLL does not use a stack.

  • An EXPORTS statement must be included, defining each function that will be exported from the DLL.

    The DLL module must be copied to a directory referenced by the LIBPATH statement in CONFIG.SYS. This is typically the C:\OS2\DLL directory, although another directory may be used if so desired.


    [Back: Dynamic Link Libraries]
    [Next: Using a DLL]