DLLs typically are used to provide common functions that can be used by a number of applications. The following figure shows a C source file, MYPUTS.C, for a DLL that contains a simple string-printing function.
#include <os2.h> #define HF_STDOUT 1 /* standard-output handle */ VOID EXPENTRY myPuts(PSZ pszMsg) { ULONG ulWritten; while(*pszMsg) { DosWrite(HF_STDOUT, pszMsg, 1, &ulWritten); pszMsg++; } }
The following figure shows the module-definition file, MYPUTS.DEF, for this DLL.
LIBRARY myputs DATA SINGLE SHARED EXPORTS myPuts
The LIBRARY statement names the DLL (MYPUTS.DLL). The DATA statement tells the system that this DLL will share all data with each process that uses the DLL. The EXPORTS statement indicates that the function myPuts can be used by applications and DLLs.
The DLL is compiled and linked like any application. You can use IBM's ICC and LINK386, as shown below, to create MYPUTS.DLL.
icc /C+ /Ge- myputs.c link386 /noi myputs, , nul, OS2386, myputs
When the DLL has been created, you must copy it to one of the directories indicated by the LIBPATH environment variable in your CONFIG.SYS file.