OpenersNotesSection(Spacer1)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 (NonWLLink[MLError(), paclet:ref/c/MLError]) to retrieve the error code if MLSetMessageHandler() fails.

(NonWLLink[MLMessageHandlerObject, paclet:ref/c/MLMessageHandlerObject]) is a pointer to a function of the form void f((NonWLLink[MLINK, paclet:ref/c/MLINK]) link,int m1,int m2).

MLSetMessageHandler() is declared in the MathLink header file (RefLink[mathlink.h, paclet:ref/file/mathlink.h]).

OpenersPrimaryExamplesSection(Spacer1)Examples  (1)

OpenersExampleSection0(Spacer1)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;
}

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(NonWLLink[MLGetMessageHandler(), paclet:ref/c/MLGetMessageHandler])  ▪  (NonWLLink[MLPutMessage(), paclet:ref/c/MLPutMessage])  ▪  (NonWLLink[MLGetMessage(), paclet:ref/c/MLGetMessage])}})}})