필터 지우기
필터 지우기

Error "Access violation executing location 0x00000000" when using mwArray in Visual-C++

조회 수: 12 (최근 30일)
I am trying to use Matlab function in VSC++ mfc 2012 to edit image. I got an this error:
Unhandled exception at 0x74E9C9F1 in pa2sample.exe: 0xC0000005: Access violation executing location 0x00000000
when I use mwArray. This is my code in C++:
BYTE* im=new BYTE();
ImgProc(1,mwArray (im),mwArray(img));
This code will use the Matlab function to convert image into grayscale image. img variable is the BYTE pointer to the buffer where image places. im variable is the output image.
ImgProc is a Matlab function:
function im=ImgProc(x)
im=rgb2gray(x);
Here is the ImgProc C++ function after converted from Matlab
ImgProc(int nargout, mwArray& im, const mwArray& x);
I appreciate if someone could help me. I have got stuck for 2 days.

답변 (1개)

Friedrich
Friedrich 2013년 10월 22일
편집: Friedrich 2013년 10월 22일
Hi,
you don't need to allocate memory for the output. MATLAB will do this for you:
mwArray out;
ImgProc(1,out,mwArray(img));
Also are you sure the call to mwArray(img) succeeds? What is img (data type and size)? AFAIK there is no constructor which would match your usecase here
  댓글 수: 12
Friedrich
Friedrich 2013년 10월 23일
Does the call to ImgProcInitialize succeed? It also has a return value? What datatype dies sFileName have?
chaocanha
chaocanha 2013년 10월 23일
편집: chaocanha 2013년 10월 23일
sFileName is CString which contains the video file path.
CFileDialog dlgFile(TRUE, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, _T("Movie Files (*.avi;*.mpg;*.mp4)|*.avi;*.mpg;*.mp4||"), this);
CString sFileName = dlgFile.GetPathName();
bool a=mclInitializeApplication(NULL,0);
bool b= ImgProcInitialize();
mwArray out(sFileName);
ImgProc(out);
ImgProcTerminate();
mclTerminateApplication();
ImgProcInitialize() returns true which is fine. Im wondering if the lines are true because I dont know how to check value of it:
mwArray out(sFileName);
ImgProc(out);
Edit: The error looks like:
Microsoft C++ exception: mwException at memory location

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Deploy to C++ Applications Using mwArray API (C++03)에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by