matOpen in C++ ... access violation errors

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++ 

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,

#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*
	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.

9/12/2007 10:59:59 AM
comp.soft-sys.matlab 211264 articles. 25 followers. lunamoonmoon (257) is leader. Post Follow

2 Replies

Similar Articles

[PageSpeed] 26

i think it could be pointer problem !! 
matlab does not have pointers 

9/12/2007 9:15:28 PM
"A " <dragonboy.ali@gmail.com> wrote in message 
> i think it could be pointer problem !! 
> matlab does not have pointers 

Matlab can use pointers if you want it to - I've used them 
in the past when loading in C/C++ libraries into Matlab. 

However, everything seems to be working better now - I re-
referenced all of the Matlab libraries to make sure they 
were up to date and discovered one of my libs was for the 
wrong compiler. Ah.

Thanks for the help. Hopeully its sorted now
9/13/2007 9:34:39 AM