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 22:33:02 +0000 (UTC)
Organization: Harman Industries International
Lines: 39
Message-ID: <gokb6u$9kg$1@fred.mathworks.com>
References: <goimue$6j6$1@fred.mathworks.com> <op.up8j75y1a5ziv5@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 1236119582 9872 172.30.248.37 (3 Mar 2009 22:33:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 3 Mar 2009 22:33:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 57524
Xref: news.mathworks.com comp.soft-sys.matlab:522275


"Ashish Uthama" <first.last@mathworks.com> wrote in message <op.up8j75y1a5ziv5@uthamaa.dhcp.mathworks.com>...
> On Tue, 03 Mar 2009 16:19:03 -0500, James Tursa  
> <aclassyguywithaknotac@hotmail.com> wrote:
> 
> > "Ashish Uthama" <first.last@mathworks.com> wrote in message  
> > <op.up8he7c6a5ziv5@uthamaa.dhcp.mathworks.com>...
> >>
> >> 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
> >>
> >
> > Couple of typos. Since dims is an array, it will act as a double * when  
> > passed, so you don't need the &dims in the call, just dims. And you are  
> > missing a comma in the dims initialization. Also, mxGetPr returns a  
> > pointer result that is not an lvalue. You need to dereference it for the  
> > assignment. e.g.
> >
> >  mxArray* prhs[3];
> >  mwSize dims[2]={ 1, 1};
> >  prhs[0]=mxCreateNumericArray(2,dims, mxDOUBLE_CLASS,mxREAL);
> >  *(mexGetPr(prhs[0])) = x;
> >
> > Or, as you almost pointed out, you can use mxCreateDoubleScalar for this:
> >
> > prhs[0] = mxCreateDoubleScalar(x);
> >
> > James Tursa
> 
> 
> not typos..but plain errors :)
> thanks for the corrections.

Thanks for the tips, I'll try it tonight.  Also wondering if COM would also work to get the data stream from the third party dll into Matlab, and if there is any advantage?  Or if there is any other way that might be better than the callback method I'm currently trying.   The data is from a camera based headtracking unit (TrackIR/Optitrack).  I have the source code for the dll, but only marginal skills in C++...