MLSetMessageHandler (C Function)
MLSetMessageHandler has been replaced by WSSetMessageHandler.
int MLSetMessageHandler(MLINK link,MLMessageHandlerObject h)
installs the urgent message handler function referenced by h for for link.
Details

- The urgent message handler function is called when MathLink receives an urgent message from the other end of the connection.
- MLSetMessageHandler() returns 0 in the event of an error, and a nonzero value if the function succeeds.
- Use MLError() to retrieve the error code if MLSetMessageHandler() fails.
- MLMessageHandlerObject is a pointer to a function of the form void f(MLINK link,int m1,int m2).
- MLSetMessageHandler() is declared in the MathLink header file mathlink.h.
Examples
Basic Examples (1)
#include "mathlink.h"
/* handle three common MathLink urgent messages */
void f(MLINK lp, int msg, int arg)
{
if(msg == MLInterruptMessage)
{ /* generate an interrupt menu */ }
else if(msg == MLAbortMessage)
{ /* abort the current operation */ }
else if(msg == MLTerminateMessage)
{ /* shutdown the program */ }
/* ... */
}
int main(int argc, char **argv)
{
MLENV env;
MLINK link;
int error;
env = MLInitialize((char *)0);
if(env == (MLENV)0)
{ /* unable to initialize MathLink environment */ }
link = MLOpenArgcArgv(env, argc, argv, &error);
if(link == (MLINK)0 || error != MLEOK)
{ /* unable to create link */ }
if(! MLSetMessageHandler(link, (MLMessageHandlerObject)f)
{ /* unable to install message handler for link */ }
/* ... */
MLClose(link);
MLDeinitialize(env);
return 0;
}