使用MATLAB Coder将代码集成到Visual Studio中

时间:2014-01-07 21:49:39

标签: c++ matlab dll access-violation matlab-coder

我使用Matlab编码器从Mathlab .m文件创建了一个dll文件。在matlab中,matlab代码运行正常,没有任何错误,DLL创建成功。 MV2010编译并运行良好。但是,当软件在Visual Studio中调用此DLL中的任何函数时,我会得到带有内存位置的“未处理异常”和带有另一个内存位置的“访问冲突读取位置”。

我认为创建的dll依赖于另一个缺失的dll。所以,我使用依赖Walker来检查依赖性。但是,依赖性walker没有显示任何缺少的依赖。

Matlab函数接受5个输入变量(4个作为double,1个作为double的1D数组)并返回4个double值。所以我认为可能是我传递给matlab生成的代码的数组的大小很小。所以,我重新调整了数组的大小。原始大小是750,而新大小是5000.仍然得到相同的未处理的例外。

知道如何调试这个未处理的异常吗?我需要检查的其他任何东西?

/ *函数声明* /

extern void mat3(double ValueF, double DesiredValue, double io, double del, emxArray_real_T *a, double *status, double *slope_deg, double *fval, double *SVal);

我在MS2010中调用此方法,如下所示。

 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);

请注意: 1)img - &gt;是输入图像数据。 2)roi - &gt;是一个struct类型的对象,它有两个int变量(x和y) 3)MV2010应用程序是一个在共享DLL中使用“MFC”的应用程序 4)我已经看过如何在Microsoft Visual Studio中集成Mathlab生成的dll的教程。但是,本教程不会出现任何错误。 http://www.mathworks.com/videos/integrate-code-into-visual-studio-77402.html

提前感谢您的帮助。

0 个答案:

没有答案