⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 comtestdoc.cpp

📁 该程序是一个matlab与visual c++ 混合编程的例子
💻 CPP
字号:
// comtestDoc.cpp : implementation of the CComtestDoc class
//

#include "stdafx.h"
#include "comtest.h"
#include "mymatrix_idl.h"
#include "comtestDoc.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CComtestDoc

IMPLEMENT_DYNCREATE(CComtestDoc, CDocument)

BEGIN_MESSAGE_MAP(CComtestDoc, CDocument)
	//{{AFX_MSG_MAP(CComtestDoc)
		// NOTE - the ClassWizard will add and remove mapping macros here.
		//    DO NOT EDIT what you see in these blocks of generated code!
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CComtestDoc construction/destruction

CComtestDoc::CComtestDoc()
{
	// TODO: add one-time construction code here

}

CComtestDoc::~CComtestDoc()
{
}

BOOL CComtestDoc::OnNewDocument()
{
	if (!CDocument::OnNewDocument())
		return FALSE;

	double a[2][2]={{2.0,-1.0},{-1.0,2.0}}; 
double b[2][2]={{0,0},{0,0}}; 




VARIANT A,x,y; 
VariantInit(&A); 
VariantInit(&x); 
VariantInit(&y); 
A.vt=VT_R8|VT_ARRAY; 
x.vt=VT_R8|VT_ARRAY; 
SAFEARRAYBOUND rgsabound[1]; 
rgsabound[0].cElements=2; 
rgsabound[0].lLbound=0; 
rgsabound[1].cElements=2; 
rgsabound[1].lLbound=0; 
A.parray=SafeArrayCreate(VT_R8,2,rgsabound); 
A.parray->pvData=a; 
x.parray=SafeArrayCreate(VT_R8,2,rgsabound); 
long ll[2];

//memcpy(a,A.parray->pvData,4*sizeof(double)); 
/*CString str1;
  str1.Format("cholesky分解结果是:\n%8.2f%10.2f\n%8.2f%10.2f\n", 
        a[0][0],a[0][1],a[1][0],a[1][1]); 
*/
HRESULT hr = CoInitialize(NULL); 
   const IID IID_Imyfactor = {0xE4FFCF1E,0x9D05,0x4F45,{0xB4,0xA5,0x1F,0x2C,0xB0,0x8C,0x39,0x59}};
   const IID LIBID_mymatrix = {0x04E59AEF,0xEFEB,0x4838,{0x9E,0xF3,0x6B,0x27,0x4A,0xFE,0x7D,0xA3}};
   const CLSID CLSID_myfactor = {0xFFD6C319,0x5B35,0x4C75,{0x96,0x91,0x2F,0x83,0xCF,0xD8,0x0D,0xD3}};


//Create an instance of the COM object 
Imyfactor pImyfactor; 
hr=pImyfactor.CreateDispatch(CLSID_myfactor,NULL); 
if(SUCCEEDED(hr)) 
{ 
pImyfactor.SetA(A); 

pImyfactor.cholesky(1,&x); 

memcpy(a,x.parray->pvData,4*sizeof(double)); 
CString str1,str2,str3; 
str1.Format("cholesky分解结果是:\n%8.2f%10.2f\n%8.2f%10.2f\n", 
        a[0][0],a[0][1],a[1][0],a[1][1]); 
AfxMessageBox(str1); 

}
	// TODO: add reinitialization code here
	// (SDI documents will reuse this document)

	return TRUE;
}



/////////////////////////////////////////////////////////////////////////////
// CComtestDoc serialization

void CComtestDoc::Serialize(CArchive& ar)
{
	if (ar.IsStoring())
	{
		// TODO: add storing code here
	}
	else
	{
		// TODO: add loading code here
	}
}

/////////////////////////////////////////////////////////////////////////////
// CComtestDoc diagnostics

#ifdef _DEBUG
void CComtestDoc::AssertValid() const
{
	CDocument::AssertValid();
}

void CComtestDoc::Dump(CDumpContext& dc) const
{
	CDocument::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CComtestDoc commands

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -