Solved

Unable to load UserObjectDefinition function from DLL

  • 12 October 2023
  • 2 replies
  • 113 views

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) 

Thanks!

Alexei

icon

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: https://stackoverflow.com/questions/1041866/what-is-the-effect-of-extern-c-in-c.

Please let us know otherwise.

Take care,


David

Hi David,

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

https://support.zemax.com/hc/en-us/articles/1500005577602-How-to-compile-a-User-Defined-DLL.

Take care,

Alexei

 

Reply