Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: mex file wrapper for dll needing function handle
Date: Tue, 3 Mar 2009 21:19:03 +0000 (UTC)
Organization: Boeing
Lines: 24
Message-ID: <gok6s7$6oc$1@fred.mathworks.com>
References: <goimue$6j6$1@fred.mathworks.com> <op.up8he7c6a5ziv5@uthamaa.dhcp.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1236115143 6924 172.30.248.38 (3 Mar 2009 21:19:03 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 3 Mar 2009 21:19:03 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 756104
Xref: news.mathworks.com comp.soft-sys.matlab:522240


"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