当前位置:文档之家› Matlab调用MFC应用实例

Matlab调用MFC应用实例

//MainFunction.cpp#include "stdafx.h"#include "mex.h"#include "MFCDialog.h"voidmexFunction(intnlhs, mxArray *plhs[], intnrhs, constmxArray *prhs[]) {mxArray *pa=NULL;double *x=NULL;double *y=NULL;double *result=NULL;charstrbuf[50];if(nrhs!=2){mexErrMsgTxt("You can only input 2 arguements!");return;}else{x=mxGetPr(prhs[0]);y=mxGetPr(prhs[1]);sprintf(strbuf,"x=%f,y=%f",*x,*y);mexPrintf(strbuf);plhs[0]=mxCreateDoubleMatrix(1,2,mxREAL);result=mxGetPr(plhs[0]);result[0]=*x;result[1]=*y;mexPrintf("\nStart MFC\n");MFCDialog *a;a=new MFCDialog();if(a->DoModal()==IDCANCEL){mexPrintf("Exit MFC\n");}mexPrintf("End MFC\n");}}// MFCDialog.cpp : implementation file//#include "stdafx.h"#include "MFCPlot.h"#include "MFCDialog.h"#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE[] = __FILE__;#endif/////////////////////////////////////////////////////////////////////////////// MFCDialog dialogMFCDialog::MFCDialog(CWnd* pParent /*=NULL*/): CDialog(MFCDialog::IDD, pParent){//{{AFX_DATA_INIT(MFCDialog)// NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT}voidMFCDialog::DoDataExchange(CDataExchange* pDX){CDialog::DoDataExchange(pDX);//{{AFX_DATA_MAP(MFCDialog)// NOTE: the ClassWizard will add DDX and DDV calls here //}}AFX_DATA_MAP}BEGIN_MESSAGE_MAP(MFCDialog, CDialog)//{{AFX_MSG_MAP(MFCDialog)// NOTE: the ClassWizard will add message map macros here //}}AFX_MSG_MAPEND_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////// MFCDialog message handlers// MFCPlot.cpp : Defines the initialization routines for the DLL.//#include "stdafx.h"#include "MFCPlot.h"#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE[] = __FILE__;#endif//// Note!//// If this DLL is dynamically linked against the MFC// DLLs, any functions exported from this DLL which// call into MFC must have the AFX_MANAGE_STATE macro // added at the very beginning of the function.//// For example://// extern "C" BOOL PASCAL EXPORT ExportedFunction()// {// AFX_MANAGE_STATE(AfxGetStaticModuleState()); // // normal function body here// }//// It is very important that this macro appear in each// function, prior to any calls into MFC. This means that// it must appear as the first statement within the// function, even before any object variable declarations// as their constructors may generate calls into the MFC// DLL.//// Please see MFC Technical Notes 33 and 58 for additional // details./////////////////////////////////////////////////////////////////////////////// // CMFCPlotAppBEGIN_MESSAGE_MAP(CMFCPlotApp, CWinApp)//{{AFX_MSG_MAP(CMFCPlotApp)// NOTE - the ClassWizard will add and remove mapping macros here.// DO NOT EDIT what you see in these blocks of generated code!//}}AFX_MSG_MAPEND_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////// CMFCPlotApp constructionCMFCPlotApp::CMFCPlotApp(){// TODO: add construction code here,// Place all significant initialization in InitInstance}/////////////////////////////////////////////////////////////////////////////// The one and only CMFCPlotApp objectCMFCPlotApptheApp;; MFCPlot.def : Declares the module parameters for the DLL.LIBRARY "MFCPlot"DESCRIPTION 'MFCPlot Windows Dynamic Link Library'EXPORTS; Explicit exports can go heremexFunction// stdafx.cpp : source file that includes just the standard includes// MFCPlot.pch will be the pre-compiled header// stdafx.obj will contain the pre-compiled type information#include "stdafx.h"#if !defined(AFX_MFCDIALOG_H__543ADFB6_3136_4D44_B9E6_075E1F9DFD03__INCLUDED _)#define AFX_MFCDIALOG_H__543ADFB6_3136_4D44_B9E6_075E1F9DFD03__INCLUDED_#if _MSC_VER > 1000#pragma once#endif // _MSC_VER > 1000// MFCDialog.h : header file//#include "resource.h"/////////////////////////////////////////////////////////////////////////////// MFCDialog dialogclassMFCDialog : public CDialog{// Constructionpublic:MFCDialog(CWnd* pParent = NULL); // standard constructor// Dialog Data//{{AFX_DATA(MFCDialog)enum { IDD = IDD_DIALOG };// NOTE: the ClassWizard will add data members here //}}AFX_DATA// Overrides// ClassWizard generated virtual function overrides//{{AFX_VIRTUAL(MFCDialog)protected:virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support //}}AFX_VIRTUAL// Implementationprotected:// Generated message map functions//{{AFX_MSG(MFCDialog)// NOTE: the ClassWizard will add member functions here//}}AFX_MSGDECLARE_MESSAGE_MAP()};//{{AFX_INSERT_LOCATION}}// Microsoft Visual C++ will insert additional declarations immediately before the previous line.#endif// !defined(AFX_MFCDIALOG_H__543ADFB6_3136_4D44_B9E6_075E1F9DFD03__INCLUDED_)// MFCPlot.h : main header file for the MFCPLOT DLL//#if !defined(AFX_MFCPLOT_H__6A1F0D27_6E86_47D8_BA48_0E195799BD15__INCLUDED_) #define AFX_MFCPLOT_H__6A1F0D27_6E86_47D8_BA48_0E195799BD15__INCLUDED_#if _MSC_VER > 1000#pragma once#endif // _MSC_VER > 1000#ifndef __AFXWIN_H__#error include 'stdafx.h' before including this file for PCH#endif#include "resource.h" // main symbols/////////////////////////////////////////////////////////////////////////////// CMFCPlotApp// See MFCPlot.cpp for the implementation of this class//classCMFCPlotApp : public CWinApp{public:CMFCPlotApp();// Overrides// ClassWizard generated virtual function overrides//{{AFX_VIRTUAL(CMFCPlotApp)//}}AFX_VIRTUAL//{{AFX_MSG(CMFCPlotApp)// NOTE - the ClassWizard will add and remove member functions here.// DO NOT EDIT what you see in these blocks of generated code !//}}AFX_MSGDECLARE_MESSAGE_MAP()};///////////////////////////////////////////////////////////////////////////////{{AFX_INSERT_LOCATION}}// Microsoft Visual C++ will insert additional declarations immediately before the previous line.#endif// !defined(AFX_MFCPLOT_H__6A1F0D27_6E86_47D8_BA48_0E195799BD15__INCLUDED_)//{{NO_DEPENDENCIES}}// Microsoft Developer Studio generated include file.// Used by MFCPlot.rc//#define IDD_DIALOG 3000// Next default values for new objects//#ifdef APSTUDIO_INVOKED#ifndef APSTUDIO_READONLY_SYMBOLS#define _APS_NEXT_RESOURCE_VALUE 3001#define _APS_NEXT_COMMAND_VALUE 32771#define _APS_NEXT_CONTROL_VALUE 3000#define _APS_NEXT_SYMED_VALUE 3000#endif#endif// stdafx.h : include file for standard system include files,// or project specific include files that are used frequently, but// are changed infrequently//#if !defined(AFX_STDAFX_H__ED1F4467_E80C_41BC_8353_8D4B463DC0AE__INCLUDED_) #define AFX_STDAFX_H__ED1F4467_E80C_41BC_8353_8D4B463DC0AE__INCLUDED_#if _MSC_VER > 1000#pragma once#endif // _MSC_VER > 1000#define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers#include <afxwin.h> // MFC core and standard components#include <afxext.h> // MFC extensions#ifndef _AFX_NO_OLE_SUPPORT#include <afxole.h> // MFC OLE classes#include <afxodlgs.h> // MFC OLE dialog classes#include <afxdisp.h> // MFC Automation classes#endif // _AFX_NO_OLE_SUPPORT#ifndef _AFX_NO_DB_SUPPORT#include <afxdb.h> // MFC ODBC database classes#endif // _AFX_NO_DB_SUPPORT#ifndef _AFX_NO_DAO_SUPPORT#include <afxdao.h> // MFC DAO database classes#endif // _AFX_NO_DAO_SUPPORT#include <afxdtctl.h> // MFC support for Internet Explorer 4 Common Controls#ifndef _AFX_NO_AFXCMN_SUPPORT#include <afxcmn.h> // MFC support for Windows Common Controls#endif // _AFX_NO_AFXCMN_SUPPORT//{{AFX_INSERT_LOCATION}}// Microsoft Visual C++ will insert additional declarations immediately before the previous line.#endif// !defined(AFX_STDAFX_H__ED1F4467_E80C_41BC_8353_8D4B463DC0AE__INCLUDED_)。

相关主题