Skip to main content
Solved

Unable to load UserObjectDefinition function from DLL

  • October 12, 2023
  • 2 replies
  • 201 views

Aliaksei.Kobylinskiy

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

Best answer by David.Nguyen

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

2 replies

David.Nguyen
Luminary
Forum|alt.badge.img+2
  • Luminary
  • Answer
  • October 13, 2023

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


Aliaksei.Kobylinskiy

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