I created a dll file from Mathlab .m files using Matlab coder. In matlab, the matlab code runs fine without any error and DLL creation was successful. MV2010 compiles and runs fine. However, when the software calls any function from this DLL in Visual studio, i get "unhandled exception" with memory location and "access violation reading location" with another memory location.
I thought the created dll is depending on another dll that is missing. So, I used dependency Walker to check the dependency. However, dependency walker did not show any missing dependency.
The Matlab functions takes 5 input variables ( four as a double and one as 1D-array of double) and return 4 double values. So I thought it might be the size of the array i am passing to the matlab-generated code is small. So, I re-sized the array. The original size was 750, while new size is 5000. Still getting the same unhandled exception.
Any idea how to debug this unhandled exception? anything else i need to check for?
/* Function Declarations */
extern void mat3(double ValueF, double DesiredValue, double io, double del, emxArray_real_T *a, double *status, double *slope_deg, double *fval, double *SVal);
and I am calling this method in MS2010 as shown below.
double lValueF = 166.6;
double lDesiredValue = 42.00;
double io = 1.0;
double del = 4.0;
emxArray_real_T *lInputRoi;
// a = emxCreate_real_T(height,width);
lInputRoi = emxCreate_real_T(size_y,size_x);
// Converting 2D image to ID array
if(!isHorz)
{
int lRow = 0;
int lCol = 0;
for (int row=roi.y+odd_y_offset;row< roi.y+size_y;row=row+2)
{
lCol = 0;
for (int col=roi.x;col< roi.x+size_x;col++)
{
lInputRoi->data[lRow *size_x + lCol] = (real_T)img.at<uchar>(row,col);
lCol++;
}
lRow++;
}
}
else
{
int lRow = 0;
int lCol = 0;
for (int col=roi.x+odd_x_offset;col< roi.x+size_x;col=col+2)
{
lRow = 0;
for (int row=roi.y;row< roi.y+size_y;row++)
{
lInputRoi->data[lCol *size_y + lRow] = (real_T)img.at<uchar>(row,col);
lRow++;
}
lCol++;
size_x = roi.height;
size_y = roi.width;
}
}
// initializing matlab generated function
mat3_initialize();
double lStatus = 0;
double lslope_deg = 0.0;
double lfreqval = 0.0;
double lsfrvalue = 0.0;
mat3(lValueF, lDesiredValue, io, del, lInputRoi, &lStatus, &lslope_deg, &lfreqval, &lsfrvalue);
note: 1) img -> is the input image data. 2) roi -> is an object of struct type that has two int variables (x and y) 3) MV2010 application is an application that used "MFC in a shared DLL" 4) I have seen a tutorial on how to integrate the Mathlab generated dll in Microsoft Visual studio. However, the tutorial does not get any error. http://www.mathworks.com/videos/integrate-code-into-visual-studio-77402.html
Thanks you for any help in advance.