Unable to load UserObjectDefinition function from DLL

  • 12 October 2023
  • 2 replies

Hi, could somebody help me, why I can not use a compiled dll using the code from native cpp-file CoatingSample.cpp? Zemax says “Unable to load "UserObjectDefinition" function from DLL”. I hoped, the code from cpp-files are fully ready to become a dll.

 (Of course, if I use a native dll called “CoatingSample.DLL” everything works) 




Best answer by David.Nguyen 13 October 2023, 11:57

View original

2 replies

Userlevel 7
Badge +2

Hi @Aliaksei.Kobylinskiy,


I believe the CoatingSample file shipped with OpticStudio is a C file: CoatingSample.c

If you are trying to convert it to a C++ file, it is necessary but not sufficent to change the extension to: CoatingSample.cpp

I don’t have time to thoroughly test, but I believe if you replace those lines (13-14) in the original file:

int __declspec(dllexport) APIENTRY UserObjectDefinition(double *data, double *tri_list);
int __declspec(dllexport) APIENTRY UserParamNames(char *data);

by the following lines:

extern "C" {
int __declspec(dllexport) APIENTRY UserObjectDefinition(double* data, double* tri_list);
int __declspec(dllexport) APIENTRY UserParamNames(char* data);

It should correct the issue. This can provide more information:

Please let us know otherwise.

Take care,


Hi David,

Thank you so much! Yes, it works. Thank you also for the link. And yes, it is also described in :

Take care,