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

📄 zhsl.txt

📁 这是机械工业张德丰《MATLAB与外部程序接口编程》随书源码
💻 TXT
字号:
#include "mwCOMtypes.h"
#include "mytestCOM_idl_i.c"
#include "mytestCOM_idl.h"
void CCOMTestlDlg::OnOk ( )
{
	// TOOD: Add extra validation here

	//CDialog::OnOk ( );
	ItestCOM *tc;
	HRESULT
		hr=CoCreateInstance (CLSID_testCOM, NULL, CLSCTX_ALL, IID_ItestCOM, (void **) &tc);
	if (FAILED (hr))
	{
		AfxMessageBox ("fail");
		return;
	}
	double xdata[2][2]={1.0, 2.0, 3.0, 4.0};
	double ydata=0;
	double tmpdata=0;
	VARIANT x, y, tmp;
	VariantInit (&x);
	VariantInit (&y);
	VariantInit (&tmp);
	x.vt=VT_R8 | VT_ARRAY;
	SAFEARRAYBOUND  bound[2];
	bound[0].cElements=2;
	bound[0].lLbound=0;
	bound[1].cElements=2;
	bound[1].lLbound=0;
	x.parray=SafeArrayCreate (VT_R8, 2, bound);
	if (x.parray = = NULL)
	{
		AfxMessageBox ("!fail");
		return;
	}
	x.parray->pvData=xdata;
	//调用方法
	tc -> put_A (x);
	tc -> testproperty (1, &y);

	//显示结果
	tc -> get_A (&tmp);
	memcpy (xdata, tmp.parray -> pvData, 4*sizeof (double));
	CString str;
	str.Format ("%f, %f\n, %f", xdata[0][0], xdata [0][1], xdata [1][0], xdata [1][1]);
	MessageBox (str,"matrix",MB_OK | MB_ICONINFORMATION);
	//result
	ydata=y.dblVal;
	str.Format ("%f", ydata);
	MessageBox (str, "the value of matrix", MB_OK | MB_ICONINFORMATION);

	//析构组件实例
	tc -> Release ( );
}

⌨️ 快捷键说明

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