Clear Filters
Clear Filters

How does Matlab Compiler handle Structures (Converting a Matlab Structure to a C structure)

6 views (last 30 days)
I have been using Matlab Compiler to create a C shared library and then I will use the DLL as a plug in to another application. I followed the instructions found here: (<http://www.mathworks.com/matlabcentral/answers/94715-how-do-i-wrap-matlab-compiler-4-8-r2008a-created-c-dlls-to-create-another-dll>)
I was able to go through and create my DLL and wrap it to use as a plug in as well as test that newly wrapped function. The problem I have now is trying to return a Structure from my Matlab code into the wrapper function and the application.
I followed the example provided in the link (which I linked the applicable code below) to build a level2.dll. In my function (mlfLevel1) I need to return to variables one is just an integer number which I can convert, the other is a structure and it is what is causing me issues. I am not sure how to approach the Converting Matlab data to C data part of this code when I am trying to convert a Matlab struct to a C structure.
Thank you in advance!
/*-----------------------------------------------------------------------*/
/* Wrapper for level 1 function exported by the MATLAB generated DLL *
* This function converts C data to MATLAB data, calls the MATLAB generated *
* function in level1.dll and then converts the MATLAB data back into C data */
int wmlfLevel1(double* input2D, int size, char* message, double** output2d){
int nargout=1;
/* Pointers to MATLAB data */
mxArray *msg;
mxArray *in2d;
mxArray *out2d=NULL;
/* Start MCR, load library if not done already */
int returnval=isMCRrunning();
if(!returnval)
return returnval;
/* Convert C data to MATLAB data */
/* IMPORTANT: this has to be done after ensuring that the MCR is running */
msg=mxCreateString(message);
in2d=mxCreateDoubleMatrix(size, size, mxREAL);
memcpy(mxGetPr(in2d), input2D, size*size*sizeof(double));
/* Call the M function */
returnval=mlfLevel1(nargout, &out2d, in2d, msg);
/*Convert returned MATLAB data to C data */
*output2d=(double *)malloc(sizeof(double)*size*size);
memcpy(*output2d, mxGetPr(out2d), size*size*sizeof(double));
/* Clean up MATLAB variables */
mxDestroyArray(msg);
mxDestroyArray(in2d);
mxDestroyArray(out2d);
return returnval;
}

Answers (0)

Categories

Find more on MATLAB Compiler in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!