The SOM run-time environment uses SOM functions that perform memory management, DLL management, character output, and error handling. These functions are replaceable, which means that you can override them by supplying your own version of the default SOM functions.

The following sample code shows how a user-defined function can be substituted for one of the replaceable SOM functions:

#define INCL_DOS
#define INCL_WINWORKPLACE

#include <os2.h>
#include <io.h>
#include <stdio.h>
#include <fcntl.h>
#include <sys\stat.h>
#include <string.h>
#include <som.h>

static FILE   *ErrorFile;     /* File to contain debugging error information */

/*
 * This is the replacement for the default SOMOutCharRoutine.
 * It writes the debugging information to a file on the hard drive.
 */

#pragma linkage(myCharacterOutputRoutine, system)

int  SOMLINK  myCharacterOutputRoutine (char chOut)
{
    fputc ((int) chOut, ErrorFile);
    fflush(ErrorFile);
    return 1;   /* Indicate success */
}

/*
 *   Enable myCharacterOutputRoutine by opening the output error
 *   file and then changing the output character routine.
 */

ErrorFile = fopen ("c:\\error.txt", "a" ;

fprintf (ErrorFile, "\nDebug information from my WPS Object\n");
fprintf (ErrorFile,   "------------------------------------\n");
setbuf (ErrorFile, NULL);

SOM_TraceLevel = 2;   /* Request maximum debugging information */
SOM_WarnLevel  = 2;

/* All output goes to my routine after the next statement */

SOMOutCharRoutine = myCharacterOutputRoutine;


[Back] [Next]