User`s guide

Print Handlers
5-45
The applic at io n is buil t from two fil es:
mrankwin.c, which contains WinMain, WinPrint (the print handler), a nd a
related function
WinFlush
The MATLAB Compiler C translation of mrank.m
Both mrankwin.c and mrank.m are located in the
<matlab>/extern/examples/compiler/ directo ry of your installati on.
The
WinMain routine in mrankwin.c is stra ightforward:
It registers a print handler.
It assigns an integer input from the command line to a scalar array, or
defaults the contents of the array to 12.
It passes that array to
mlfMrank, which determines the rank of the magic
squares from 1 to n.
It prints the array returned by
mlfMrank.
The first and last items in this list refer to print handlers.
Registering a Print Handler
To register a print handler routine, call the MATLAB C Math Library routine
mlfSetPrintHandler as the first executable line in WinMain (or main).
mlfSetPrintHander takes a single argument, a pointer to a print handler
function.
For example, thefirstlineof
WinMain inmrankwin.c registersthe printhandler
routine named
WinPrint by calling mlfSetPrintHandler.
mlfSetPrintHandler(WinPrint);
Writing a Print Handler
When ever an mlf functionwithina stand-alone application makes a requestto
write data, t he application automat icall y inte rcepts t he re quest and cal ls t he
regist ered print handler, passing the te xt t o b e dis play e d. I n f act, the
application c alls the print handler once fo r every lineofdatatobeoutput.