WSMessageHandlerObject (C 函数)
是一个 WSTP 类型,描述一个接受三个自变量:一个 WSLINK、一个 int 和一个 int 的函数的函数指针,并返回一个实现紧急消息处理程序的 void.
范例
基本范例 (1)
#include "wstp.h"
/* handle three common WSTP urgent messages */
void f(WSLINK lp, int msg, int arg)
{
if(msg == WSInterruptMessage)
{ /* generate an interrupt menu */ }
else if(msg == WSAbortMessage)
{ /* abort the current operation */ }
else if(msg == WSTerminateMessage)
{ /* shutdown the program */ }
/* ... */
}
int main(int argc, char **argv)
{
WSENV env;
WSLINK link;
int error;
env = WSInitialize((WSEnvironmentParameter)0);
if(env == (WSENV)0)
{ /* unable to initialize WSTP environment */ }
link = WSOpenArgcArgv(env, argc, argv, &error);
if(link == (WSLINK)0 || error != WSEOK)
{ /* unable to create link */ }
if(! WSSetMessageHandler(link, (WSMessageHandlerObject)f)
{ /* unable to install message handler for link */ }
/* ... */
WSClose(link);
WSDeinitialize(env);
return 0;
}