Path: news.mathworks.com!not-for-mail
From: "David Doria" <daviddoria@gmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: Call a MEX function from Matlab Engine?
Date: Thu, 13 Mar 2008 20:55:21 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 26
Message-ID: <frc4bp$ipi$1@fred.mathworks.com>
Reply-To: "David Doria" <daviddoria@gmail.com>
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 1205441721 19250 172.30.248.38 (13 Mar 2008 20:55:21 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 13 Mar 2008 20:55:21 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1105197
Xref: news.mathworks.com comp.soft-sys.matlab:457134



I have a mex file test.mexw32 in
'C:\Documents and Settings\Dave\My Documents\Visual Studio
2005\Projects\Matlab MEX'

My function simply squares the input.  In matlab, test(4)
tells me 16.

Now in my c++ code, I did this:

engEvalString(ep, "cd 'C:\Documents and Settings\Dave\My
Documents\Visual Studio 2005\Projects\Matlab MEX';");

engEvalString(ep, "a=test(4);");
mxArray *test2 = NULL;
test2 = mxCreateDoubleMatrix(1, 1, mxREAL);
test2 = engGetVariable(ep, "a");
double *myout2;
myout2 = mxGetPr(test2);
cout << myout2[0] << endl;

I get a "Access violation reading location" error. What have
I done wrong?

Thanks,

Dave