setmmsg - set custom message handler function


#include "windows.h"
#include "stdio.h"
#include "stdarg.h"
#include "api3.h"
#include "mmsg.h"

void FAR setmmsg(newfunction)
int (FAR *newfunction)(int msgn, char FAR *fn, char FAR *fmt,
                       va_list args);

Setmmsg() will set the function to call to handle messages from putmsg(). The handler function will receive four arguments:

1: int msgn;     the message number       (same as putmsg())
2: char *fn;     the function name        (same as putmsg())
3: char *fmt;    the htpf format string   (same as putmsg())
4: va_list args; the stdarg argument list as derived in putmsg()
by the va_start() call.

The args variable may be used like any va_list that has been va_start()'d. e.g. in a call to WVSPRINTF(). Do not call va_end() on args.

The handler function pointer must be the result of the Windows MakeProcInstance() call so that it can be called correctly from within the Metamorph API DLL. See your Windows SDK manual for details on MakeProcInstance(). You should not use MakeProcInstance() more than once for any given function if possible. Each call to it will use a little memory.

The return value of the handler function will be returned by putmsg() to the original caller.



                                     /* a custom message handler */
msghandler(int n,char FAR *fn,char FAR *fmt,va_list args)
static char buf[256];                     /* place to sprintf to */
char        *d;

   if(n>=0 && n<100)        strcpy(buf,"ERROR: ");
   else if(n>=100 && n<200) strcpy(buf,"WARNING: ");
   else                     strcpy(buf,"FYI: ");
   if(fmt!=(char *)NULL){
      d = buf + strlen(buf);
      htsnpf(d, (buf + sizeof(buf)) - d, fmt, args);
   if(fn!=(char *)NULL){
      strcat(buf," In the function: ");
            /* display message in a standard windows message box */
   MessageBox(GetFocus(),(LPSTR)buf,(LPSTR)"Metamorph 3 Message",MB_OK);


HANDLE hInst;                              /* current instance */
APICP *acp;


   putmsg(MINFO,(char *)NULL,"Default handler active");




      putmsg(MINFO,(char *)NULL,"My custom handler active");



   acp=openapicp();          /* open mm api control parameters */

Windows programs are generally case insensitive pascal calling sequence. Using the Metamorph API under Borland C with case sensitivity and C calling sequence as defaults requires a little adjustment.

Borland C options:

  1. Windows large model exe.

  2. define_WINDOWS.

  3. Borland C++ source (detect C/C++ by extension).

  4. Case sensitive exports as well as case sensitive link.

api3.h modifications:

  1. Insert the "pascal" keyword before each function name in its prototype.

  2. Redefine all functions as uppercase before their prototypes. (e.g. "#define rdmmapi RDMMAPI")

Copyright © Thunderstone Software     Last updated: Apr 15 2024
Copyright © 2024 Thunderstone Software LLC. All rights reserved.