MATLAB: Can I pass a pointer to a C struct to a C/C++ library created with MATLAB compiler

compilerlibraryMATLABMATLAB Compiler SDKpointerssdk

Can I pass a pointer to a C struct to a C/C++ library created with MATLAB Compiler SDK?

Best Answer

It is is not possible to pass a pointer to a native C structure directly to a compiled MATLAB function.
Data sent to your compiled MATLAB function has to be in a format MATLAB understands; MATLAB cannot use pointers to C structs.
If you are integrating your library into a C++ application you will need to create instances of 'mwArray' for each of your inputs to the compiled MATLAB function. The mwArrays are then passed by reference to your MATLAB shared library function. This requires copying fields from your C structures into MATLAB structures. For more information, refer to the following link:
If you create are integrating your library into a C application you will need to create mxArrays and pass pointers to the mxArrays to the compiled MATLAB function. This requires copying fields from your C structures into MATLAB structures. For more information, refer to the following documentation: