Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

MathLink message handler not set by default

  • To: mathgroup at smc.vnet.net
  • Subject: [mg96794] MathLink message handler not set by default
  • From: Arnaud <arnaudkoetsier at gmail.com>
  • Date: Wed, 25 Feb 2009 04:02:50 -0500 (EST)

I struggled for a while to make my MathLink program (compiled for MS
Windows in VC++ Express 2008) abortable following the procedure laid
out in the MathLink tutorial to no avail; the global MLAbort variable
which is supposed to become 1 when an abort message is sent by the
kernel was never changed from zero despite regular calls to the yield
function. While checking if kernel messages were getting through, in
one of my routines I did

printf("Message Handler address: %p\n",MLMessageHandler(stdlink));

which printed zero indicating there was no valid message handler. The
entry point of my program was the usual:

int main(int argc, char *argv[]) {
 return MLMain(argc, argv);
}

After rummaging around the mprep-generated C file, I noticed the point
where the yield function should be set:

if( MLInstance){
	if( stdyielder) MLSetYieldFunction( mlp, stdyielder);
	if( stdhandler) MLSetMessageHandler( mlp, stdhandler);
}

The problem is that MLInstance=0 always. I don't know what this
variable is, it looks like a pointer that is set in some windows-
related procedure called MLInitializeIcon(). As a work-around, before
the return statement in main() I inserted:

if(!MLInstance) MLInstance=(HANDLE)1;

which forced the message handler to be set and now my program receives
messages from the kernel as it should and aborts properly.

Does anyone know why the message handler isn't set by itself or what
MLInstance is?


  • Prev by Date: RE: listing user defined, independent variables
  • Next by Date: Re: Re: Re: question related to (-1)^(1/3)
  • Previous by thread: Re: Map and functional constructs to replace iterative statements
  • Next by thread: Series of Percentage Changes