您的位置:e800网站 > 技术客频道 > C++ > C++编程

C++和C#编写调用COM组件

2009-02-11 15:44:28.0      来源:中国IT实验室        
关键词:  C++     C#     COM  

(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);
};

[上一页]   [第1页]   [第2页]   [第3页]   [第4页]   [第5页]   [下一页]

关于e800 | 广告服务 | 招聘信息 | 用户注册 | 用户反馈 | 合作伙伴 | 版权声明 | 网站地图

Copyright © 2002-2010 北京亿八佰电子商务有限公司 版权所有,未经许可不得转载

联系: webmaster@e800.com.cn 电话: (8610)65612161

京ICP证040593号