What you are trying to do is dangerous because you pass the source pointers to some C ++ code, making assumptions about what exists in this place, and execute the code based on these assumptions. But let me say that you took care of all these security issues.
You will probably want to pass the pointer to your MEX file as UINT64 (so that the code can be recompiled and used, as is done with the 64-bit MATLAB installation).
On the MATLAB side:
ptrArg = uint64(hex2dec( '00C2E4E8' )); myMexFile( ptrArg );
In your mex function:
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { if( nrhs < 1 ) {
Note. You can do the same with double, just change the mxGetClassID check to find mxDOUBLE_CLASS . In this case, the expression cast will look like this:
double *p = reinterpret_cast<double *>( *mxGetPr( prhs[0] ) );
EDIT:
What I said about making this code work on a 32-bit or 64-bit machine is true only if both machines are not oriented much. Otherwise, if you pass the 32-bit pointer to a 64-bit uint on the big-end machine and pass it to double * , you will get a pointer 0x00000000 .
You can handle content issues using the MATLAB computer function to determine the limb of a machine. If byte exchange is required, you can use swapbytes . To perform these functions from your C ++ code, use mexCallMATLABWithTrap .
Praetorian
source share