MATLAB: How to call a function that resides in a DLL from a CMEX DLL

cmexdllfunctionMATLAB Compiler

How do I call a function that resides in a DLL from a CMEX DLL?
I am trying to write a CMEX file to call from the MATLAB command line. I have been successful at completing this task in the past. However, this time I am trying to call a function that resides in a DLL and now I am not able to do this.

Best Answer

The general format for linking multiple objects is:
mex circle.c square.obj rectangle.c shapes.lib
NOTE: The MEX command compiles code using the "__cdecl" calling convention. Compiling the dll using the "__stdcall" calling convention.would lead to an error. To get the linking process to work, you need to do two things when compiling your dll:
1) Change the calling convention to "__cdecl" and
2) Export the dll function using the following: extern "C" __declspec(dllexport)