Skip to main content
Solved

Unable to load UserObjectDefinition function from DLL


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

View original
Did this topic help you find an answer to your question?

2 replies

David.Nguyen
Luminary
Forum|alt.badge.img+2
  • Luminary
  • 1097 replies
  • 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

 


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings