I'm trying to get the Matlab C/C++ API working in Visual
C++ 2005 Express. Ultimately I will want to be able to
read/write simple .mat files into my standalone C++
executable.
So far, I am just attempting to get the basics working,
but keep coming up against access violation errors eg
" Unhandled exception at 0x0001ad06 in basic.exe:
0xC0000005: Access violation reading location 0x0001ad06."
even when I am copy&paste-ing code from examples that
should work.
Can anyone point me in the right direction?? Or give me
some foolproof code that is known to work ,that I can try
out. My code to follow.
Many thanks in advance,
Kirsty
#include "stdafx.h"
#include <iostream>
using namespace std;
#include "mat.h"
#pragma comment(lib, "libmat.lib")
#pragma comment(lib, "libmx.lib")
int _tmain(int argc, _TCHAR* argv[])
{
cout<<"Hello World"<<endl;
const char *file="C:\\Temp\\myFile.mat";
const char *mode="r";
printf("Reading file %s...\n\n", file);
MATFile* pmat;
pmat = matOpen(file, mode); //ERROR occurs here*
system("PAUSE");
return 0;
}
// *interestingly although the error only ever occurs when
this line is present, it doesnt matter if this line is
nver reached - ie if we move it to after the return
clause, we still get the same error.