The final stage is to copy all this code into the DLL, with minor edits so that the ZEMAX parameters are mapped correctly to the Maple ones, declare all needed variables, and to build the dll. The source code for this surface, and the associated Maple file, are provided in the zip file you can download from the last page of this article.

After the build is finished (and any compile-time error messages are corrected) it is time for the debugging stage. This may be most complicated and time-demanding part. I use DebugView freeware utility from Sysinternals. To monitor any variable while running your DLL in Zemax you just needed to add 3 strings into source code:

1. Declare variable:
char DebugString[200];

2. Add command for output in desired place and with needed format, for example:
sprintf(DebugString, "z=%f t=%f sag=%f",z,t,sag); //will print variables z, t and sag with format determined by text in quotes
OutputDebugString (DebugString );

This example is included into attached DLL code (lines 34, 224 and 225).

After compiling with such commands it is time to start DebugView. For convenience it is best to set up filter, and for the supplied file DebugView mwas set to catch string consisting “z=”:

DebugView Filter

After loading the DLL into Zemax, DebugView will display information like following:

Debug data


Here the user can monitor the available variables and correct source, if needed.