i want to do a mixed program with vc2012, and i setup my vs like this

1 view (last 30 days)
does anyone help me.
My purpose:compiled into a ".dll/.lib/.h" write a function with MATLAB,And then use VC to call it to display the dialog box and accept the return result.
my environmental Science:win8.1 + matlab r2013a(32) + vsiual 2012(32) and I made things a 32 bit program.
1,I write my matlab m-file as:
function s=li_ret_int(type)
%input 1 or 2 or null
%output positive,negitive,or zero
if ~nargin, type=3;end;
switch (type)
case 1
s = 12345678;
case 2
s = -12345678;
otherwise
s = 0;
end;
2,i compiled my m-file use: "mcc -W lib:li_ret_int -T link:lib li_ret_int.m"
3,Environment variables path add "C:\Program Files (x86)\MATLAB\R2013a\runtime\win32;C:\Program Files (x86)\MATLAB\R2013a\bin\win32"
4,visual 2012 my project setting: C\C++ -> General Additional Include Directories: "C:\Program Files (x86)\MATLAB\R2013a\extern\include;C:\Program Files (x86)\MATLAB\R2013a\bin\win32"
C\C++ -> Code Generation -> Runtime Library: "Multi-threaded Debug DLL (/MDd)" / "Multi-threaded DLL (/MD)"
Linker - >Input ->Additional Dependencies: linked all the lib files in "C:\Program Files (x86)\MATLAB\R2013a\extern\lib\win32\microsoft\"
and in my cpp file includes:
#include "ret_int_Lib.h"
#include "engine.h"
#include "mclmcr.h"
#include "matrix.h"
#include "mclcppclass.h"
#include iostream
but the error is:
1> running this function "ret_int_LibInitialize()" error: "Unhandled exception at 0x01531A80 (mfc110d.dll) in zjTestDemo1.exe: 0xC0000005: Access violation reading location 0xF8921B50." First-chance exception at 0x01531A80 (mfc110d.dll) in zjTestDemo1.exe: 0xC0000005: Access violation reading location 0xF8921B50. Unhandled exception at 0x01531A80 (mfc110d.dll) in zjTestDemo1.exe: 0xC0000005: Access violation reading location 0xF8921B50.
2>running VC code: mxArray A = mxCreateString("a"); memcpy((void) mxGetPr(A), (void*)&init, sizeof (double)); engPutVariable(pEng, "A", A);
mxArray *B = mxCreateDoubleMatrix(2, 2, mxREAL);
Result: A = NULL; B = NULL;
thank you. chopper waiting.
  1 Comment
li
li on 19 Nov 2014
my vc code test function:
void CzjTestDemo1Dlg::OnBnClickedButton2()
{
// TODO: Add your control notification handler code here
Engine* pEng = NULL;
if (!(pEng = engOpen(NULL)))
{
printf("Open matlab enging fail!");
return;
}
if( !mclInitializeApplication(NULL,0) )
{
AfxMessageBox( "Could not initialize the application.");
exit(1);
}
if (!ret_int_LibInitialize())
{
AfxMessageBox("Could not initialize the library.");
exit(1);
}
double xxxx[1] = {0};
double inin = 0;
double yyyy[1] = {0};
double outo = 0;
//
mwArray mwXX(1, 1, mxDOUBLE_CLASS);
mwArray mwIn(1, 1, mxDOUBLE_CLASS);
mwArray mwYY(1, 1, mxDOUBLE_CLASS);
mwArray mwOut(1, 1, mxDOUBLE_CLASS);
//
mwXX.SetData((mxDouble *)&xxxx, 1);
mwIn.SetData(&inin, 1);
//
//mlxLi_ret_int(2,&mwYY, mwOut,mwXX,mwIn);
li_ret_int(1,mwOut,mwIn);
//
outo = mwOut.Get(1, 1);
// lib Terminate
ret_int_LibTerminate();
// MCR Terminate
mclTerminateApplication();
}

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!