COM组件DLL编程

COM组件的DLL编程首先需准备COM组件的DLL资源。

创建一个 “Win32 Dynamic-Link Library” 动态链接库,命名为MathDLL,编译产生的DLL文件为 MathDLL.dll.

在工程文件中添加 ISimpleMath.h头文件,表示创建一个抽象基类ISimpleMath

代码:

#ifndef _ISimpleMath_Include
#define _ISimpleMath_Include

/************ ISimpleMath.h ******/

//定义抽象基类
class ISimpleMath{
public:
virtual int sum100(int m, int n)=0;
virtual int sum200(int m,int n)=0;
};
#endif

再添加 SimpleMath.h 和 SimpleMath.cpp ,创建一个继承于抽象基类(接口)ISimpleMath 的 SimpleMath类

SimpleMath 的头文件的代码:

#ifndef _SimpleMath_Include
#define _SimpleMath_Include

/******** SimpleMath.h ********/

#include "ISimpleMath.h" //接口的头文件

//创建一个继承于抽象基类的实现类
class SimpleMath:public ISimpleMath{
public:
int _declspec(dllexport) sum100(int m, int n);
int _declspec(dllexport) sum200(int m,int n);
};
#endif

SimpleMath.cpp 实现文件的代码:

/******** SimpleMath.cpp ********/

#include "SimpleMath.h"
int SimpleMath::sum100(int m,int n){
return m+n+100;
}
int SimpleMath::sum200(int m,int n){
return m+n+200;
}

编译以上工程即可获得MathDLL。

原文地址:http://blog.163.com/c_mulder/blog/static/25545465200722101746117/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值