|
(2)VC6.0编写调用程序
使用VC6.0编写建立MFC应用程序UseCom,项目类型为MFC AppWizard(exe)
在stdafx.h添加: #import "AddCom.tlb" using namespace AddCom;
程序代码: void CUseComDlg::OnButtonUse() { // TODO: Add your control notification handler code here int dresult; float fresult; CString strResult; CoInitialize(NULL);//NULL换成0也可以 AddCom::AddComInterfacePtr p_Add(__uuidof(AddComService)); dresult = p_Add->iadd(1,2); fresult = p_Add->fadd(1.2,2.3); strResult.Format("int:%d nfloat:%f",dresult,fresult); MessageBox(strResult,"计算结果",MB_OK); CoUninitialize();
}
3、在VC6.0中编写COM组件,使用VS2005 C#调用
(1)VC6.0编写COM
使用VC6.0建立COM组件,工程类型:ATL COM AppWizard
程序代码:
接口: interface IAdd : IDispatch { [id(1), helpstring("method iadd")] HRESULT iadd([in]int a, [in]int b, [out]int * c); [id(2), helpstring("method fadd")] HRESULT fadd([in]float a, [in]float b, [out]float * c); [id(3), helpstring("method isub")] HRESULT isub([in]int a, [in]int b, [out]int * c); };
|