Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Call a MEX function from Matlab Engine?
Date: Fri, 14 Mar 2008 14:45:04 +0000 (UTC)
Organization: Boeing
Lines: 42
Message-ID: <fre31g$bk1$1@fred.mathworks.com>
References: <frc4bp$ipi$1@fred.mathworks.com> <frc7ir$s19$1@fred.mathworks.com> <frccfq$l2f$1@fred.mathworks.com> <frch5p$bdj$1@fred.mathworks.com> <frdvs6$lim$1@fred.mathworks.com>
Reply-To: <HIDDEN>
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 1205505904 11905 172.30.248.37 (14 Mar 2008 14:45:04 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 14 Mar 2008 14:45:04 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 756104
Xref: news.mathworks.com comp.soft-sys.matlab:457253



"David Doria" <daviddoria@gmail.com> wrote in message
<frdvs6$lim$1@fred.mathworks.com>...
> 
> Any more clues for me? haha
> 
> Thanks,
> Dave

This worked for me. I suspect that your MATLAB engine cannot
see your test function, so when you try to execute it and
access the answer you get garbage. Print out the values of
all the pointers before you use them to verify this. Is test
on the path where the MATLAB engine can see it?

James Tursa

#include <iostream>
#include "engine.h"

using namespace std;

int main()
{
    Engine *ep;
    
    ep = engOpen(NULL);

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

engEvalString(ep, "a=mexfunc(4);");
mxArray *test2 = NULL;
test2 = engGetVariable(ep, "a");
double *myout2;
myout2 = mxGetPr(test2); //Access violation on this line
double d;
d=*myout2;
cout << d << endl;

}