Path: news.mathworks.com!not-for-mail
From: "Todd Welti" <twelti@harman.com>
Newsgroups: comp.soft-sys.matlab
Subject: mex file wrapper for dll needing function handle
Date: Tue, 3 Mar 2009 07:41:02 +0000 (UTC)
Organization: Harman Industries International
Lines: 29
Message-ID: <goimue$6j6$1@fred.mathworks.com>
Reply-To: "Todd Welti" <twelti@harman.com>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1236066062 6758 172.30.248.37 (3 Mar 2009 07:41:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 3 Mar 2009 07:41:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 57524
Xref: news.mathworks.com comp.soft-sys.matlab:522040



I'm trying to implement this idea from tech note 1-6C8PEQ, where a mex file wrapper is used to get around the limitation in matlab that you can't pass a function handle to a loaded dll library (which would be used as a callback).  In my case the dll would return three doubles, x, y, and z into "mycallback", which I woule like to return to Matlab ("myMatCallback").  It would look like shown below.  I cant for the life of me figure out how to get x,y and z into the format of prhs for hte mexCallMatlab command.  Any suggetions appreciated.  I can compile the code in general, except for anything that I have tried to get pointers to x,y, and z and make the prhs array, generates errors like: 'cannot convert parameter 1 from 'double' to 'const mxArray *'

#include "mex.h"
#include "myAPI.h"

// Callback function
void myCallback(double x, double y, double z)
{


/* THIS IS THE PART THAT HAS ME STUMPED*/


mexCallMATLAB(0, NULL, 1, prhs,"myMatCallback");
}

// MEX Gateway
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{

void (*cbPtr)(double x, double y, double z) = NULL;
cbPtr = myCallback;

// Assume that myAPIRoutine is implemented in myAPI.dll
myAPIRoutine(cbPtr);
}