Error "Access violation executing location 0x00000000" when using mwArray in Visual-C++
Show older comments
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 Comment
Abhay Prakash
on 13 Feb 2016
Hey, have you got solution for it? Thanks in advance..
Answers (1)
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 Comments
You cannot simply convert this in an mwArray by calling mwArray(img). You need to convert that manually.
You can easily check if the call succeeds or not by split that call into two lines:
mwArray tmp = mwArray(img);
mwArray out;
ImgProc(1,out,tmp);
Set a breakpoint and take a look at the "value" of tmp. I guess its a NULL pointer.
However after what you discribed the call can't work out. Convert that device-independent bitmap (DIB) format to a mwArray manually.
chaocanha
on 22 Oct 2013
Friedrich
on 23 Oct 2013
If the call to mclInitializeApplication(Null,0) fails then the whole app cant work.
In the case you try to run the code on a machine without MATLAB: do you have installed the MCR?
In the case you are working on the same machine as you compiled the code:
- Check if you can run a simple MATLAB Compiler generated exe
- Check if the runtime\win** folder is on your environment variable PATH. E.g. for 13b 64bit you should have C:\Program Files\MATLAB\R2013b\runtime\win64 in your PATH environment variable. If not add the needed entry w.r.t to your installation folder.
- Use the shipped documentation in school to get the example. Open MATLAB and type
web([docroot '/compiler/c-shared-library-target-1.html'])
chaocanha
on 23 Oct 2013
chaocanha
on 23 Oct 2013
chaocanha
on 23 Oct 2013
Friedrich
on 23 Oct 2013
Does the call to ImgProcInitialize succeed? It also has a return value? What datatype dies sFileName have?
Categories
Find more on Deploy to C++ Applications Using mwArray API (C++03) in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!