Path: news.mathworks.com!not-for-mail
From: "Todd Welti" <twelti@harman.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: mex file wrapper for dll needing function handle
Date: Tue, 3 Mar 2009 21:36:01 +0000 (UTC)
Organization: Harman Industries International
Lines: 58
Message-ID: <gok7s1$h3t$1@fred.mathworks.com>
References: <goimue$6j6$1@fred.mathworks.com> <op.up8he7c6a5ziv5@uthamaa.dhcp.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 1236116161 17533 172.30.248.37 (3 Mar 2009 21:36:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 3 Mar 2009 21:36:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 57524
Xref: news.mathworks.com comp.soft-sys.matlab:522246


"Ashish Uthama" <first.last@mathworks.com> wrote in message <op.up8he7c6a5ziv5@uthamaa.dhcp.mathworks.com>...
> On Tue, 03 Mar 2009 02:41:02 -0500, Todd Welti <twelti@harman.com> wrote:
> 
> >
> > 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);
> > }
> >
> >
> 
Thanks, but should i use 
> mxCreateScalar will help you convert a double to a mxArray.
> 
> //air code!
> mxArray* prhs[3];
> mwSize dims[2]={ 1 1};
> prhs[0]=mxCreateNumericArray(2,&dims, mxDOUBLE_CLASS,mxREAL);
> mexGetPr(prhs[0])=x;
> //..so on for y and z
> 
> 
> 
> 
Thanks, but should i use mxCreateScalar or mcCreateNumericArray?