1, StartMATLAB 7, NewMFile, input:
Function myfun (N)
T = 0 : N;
Y = Sin (t );
Plot (y );
Save the file as follows:Myfun. m
2,InMATLABOfCommand windowRun the following command:: MCC-B csglsharedlib: mylib myfunGenerate dynamic link libraryDLL.MATLABGenerates a series of files, includingMylib. h mylib. Lib mylib. dll mylib. CTFIt is what we need here.
3InVC ++Used inMATLABThe generated dynamic link library (*. Dll)
TheTestdllappProject as an example. SetMylib. h mylib. Lib mylib. dll mylib. CTFCopyTestdllappAdd the project to the project directory. ModifyTestdllapp. cppFile:
// Testdllapp. cpp: defines the entry point for the console application.
//
# Include " Stdafx. h "
# Include < Stdio. h >
# Include " Mylib. h "
# Include " Mclmcr. h "
Int OPP ( Int N );
Void Main ( Int Argc, Char * Argv [])
{
Mylibinitialize ();
Double X = 64 ;
Mxarray * T;
T = Mxcreatedoublematrix ( 1 , 1 , Mxreal );
Memcpy (mxgetpr (t ), & X, Sizeof ( Double ));
Mlfmyfun (t );
Mxdestroyarray (t );
Mylibterminate ();
Printf ( " This is a test! \ N " );
Printf ( " % D \ n " , OPP ( 16 ));
}
Int OPP ( Int N) {
ReturnN/4*4+4;
}
4,Use menu Project/Settings, open the Project Settings property page, and enterLinkPage, inObject/library modulesIn the edit box, add a file name.Libmx. Lib libmat. Lib libeng. Lib.
5Compile and runProgram.