SYNOPSIS#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);
DESCRIPTIONSetmmsg()
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.
EXAMPLE...
/* a custom message handler */
int FAR PASCAL
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: ");
strcat(buf,fn);
}
/* display message in a standard windows message box */
MessageBox(GetFocus(),(LPSTR)buf,(LPSTR)"Metamorph 3 Message",MB_OK);
return(0);
}
...
HANDLE hInst; /* current instance */
FARPROC m;
APICP *acp;
...
putmsg(MINFO,(char *)NULL,"Default handler active");
m=MakeProcInstance(msghandler,hInst);
if(m!=(FARPROC)NULL){
setmmsg(m);
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:
Borland C++ source
(detect C/C++
by extension).api3.h modifications:
"#define rdmmapi RDMMAPI"
)