I'm having trouble learning how to use MEX files, and all of the documentation (even this one: https://www.mathworks.com/help/matlab/matlab_external/standalone-example.html#zmw57dd0e18781, which seemed simple at first but completely lost me after a couple paragraphs) is going WAY over my head.
Right now, I'm trying to use code from a .dll and I don't have the original source code, but I do have a header file with function prototypes of all of the functions that I need, all within extern "C".
So instead of changing these functions or really doing anything all that complicated, I'm just trying to use the .dll functions in my MATLAB code. Here's an example of one of my functions (I have twenty):
#include "mex.h"#include "AllFunctions.h"void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]){ if(nrhs != 0) { mexErrMsgIdAndTxt("Error: myfun.c", "Cannot have any inputs."); } if(nlhs != 1) { mexErrMsgIdAndTxt("Error: myfun.c", "One output required."); } double *output; //output /* create the output matrix */ plhs[0] = mxCreateDoubleMatrix(1,1,mxREAL); /* get a pointer to the real data in the output matrix */ output = mxGetPr(plhs[0]); /* call the computational routine */ myfun; }
It has no inputs and one output. Most of my functions have a few simple inputs and one output, and a few functions pass pointers. Loadlibrary completely fails for me, and the solutions given on multiple threads do not pertain to me, so I'm trying to use MEX's instead.
I'd like to know if this is the proper approach and maybe what I should include to make this actually work before I make twenty functions that don't work. They all work in tandem with each other, so it is very difficult to test one function and then move on from there. Thanks for helping me out.
PS: Please don't tell me I need to go study MEXs more, as I am doing so as you type up your response. If there is another thing I should be looking at, I'll be very grateful. Any help is appreciated, but please don't tell me to spend my time researching (unless its something specific) before I ask beginner questions because I did a lot of research before posting this question, and I am continuing to do so afterwards.
Best Answer