1-testmex.exe is the name of our project and exception error was occurred for our project in line
mexCallMATLAB(1, plhs, 1, prhs, "test_mex");
Sorry for duplicating name of our MEX file and the project. But, if we call any other MEX file, the exception error is still thrown.
2-If even lines after
mexCallMATLAB(1, plhs, 1, prhs, "test_mex");
is omitted, this exception error is still thrown.
Let's describe whole of work!
Step 1. Create a matlab function as follow:
function [y]= test(x)
y = x^2;
end
Step 2. Save it as test.m
step 3. Make MEX file with matlab coder. It yields a MEX file namely test_mex.mexw64.
step 4. Put test_mex.mexw64 in C++ project folder namely XYZ.
step 5. The source of the cpp file in project XYZ is:
void main(){
mxArray* plhs[1];
mxArray* prhs[1];
double *plhs_p, *prhs_p;
prhs[0] = mxCreateDoubleMatrix(1, 1, mxREAL);
prhs_p = mxGetPr(prhs[0]);
plhs[0] = mxCreateDoubleMatrix(1, 1, mxREAL);
cout << "enter number:" << endl;
cin >> prhs_p[0];
mexCallMATLAB(1, plhs, 1, prhs, "test_mex");
/*
mxDestroyArray(prhs[0]);
plhs_p = mxGetPr(plhs[0]);
cout << prhs_p[0] << "^2:" << endl;
cout << plhs_p[0] << endl;
mxDestroyArray(plhs[0]);*/
}
step 6. Compile and build XYZ successfully as a win64 project.
step 7. Run project XYZ. Get an exception error in line
mexCallMATLAB(1, plhs, 1, prhs, "test_mex");
as follow:
"Unhandled exception at 0x00000000 in XYZ.exe: 0xC0000005: Access violation at location 0x0000000000000000."
and now, we are confused about this error.
User contributions licensed under CC BY-SA 3.0