- Home
- Programming ZEMAX
- User Defined Features
- How to Compile a User-Defined Surface
How to Compile a User-Defined Surface
- By Mark Nicholson
- Published 3 October 2005
- User Defined Features
-
Rating:




Compiling a User-Defined Surface with Microsoft Visual C++ Version 6
First start Microsoft Visual C++ version 6. The click File > New and select a Win32 Dynamic Link Library. Give the project a name, and choose a directory to hold the project files:
In this case, the project name is My_asphere, Click OK, and then choose to create an empty project:
This means that the project is an empty container waiting for you to add files. In the Explorer tree on the left hand side, select "File View", and right-mouse-click on "Source Files", and select "Add Files from Folder":
In the dialog that opens, navigate to {zemaxroot}/dll and select myarray.c. Remember, this is the copy of us_arrayeven.c that you made when you followed the instructions on the bottom of page 1 of this article.
Then, in the project pane above, right-mouse-click on "Header Files", choose "Add Files From Folder", and add the file usersurf.h, which is also in the {zemaxroot}/dll folder. The project pane should now look like this:
The last thing we have to do before we can start editing our file is to set the code generation options in Microsoft Visual C++ 6. Click on Project>Settings:
Select the project itself in the tree on the left hand side, and in the C/C++ tab choose Category > Code Generation, and then choose Use Run-Time Library > Multithreaded. Then select Build > Set Active Configuration, and choose "Release":
That's all the configuration that is required! To test that the compiler works, we will make a simple modification. Double-click on my_array.c in the project explorer to open it:
Find the line in Case 0 that says "strcpy(UD->string,"Even Array");" and change the name of the surface to "My Even Array". The line of text should now read:
strcpy(UD->string,"My Even Array");
and then choose Build > Rebuild All. The dll should compile without error:
Then copy the dll from your project's /release folder into the {zemaxroot}/dll folder.
Now start ZEMAX, and select a surface to be user-defined:
In the Lens Data Editor, the name we gave the surface is shown:
Congratulations! You have compiled a user-defined surface!