MFC生成dll的区别

主要分三种:

A. 动态链接库(dll)

B.具有导出项的(dll)动态链接库

C.MFC动态链接库

对比项目:可以根据需要选择哪种dll方便

添加自定义导出功能Demo

  1. 添加导出实现接口:

A. 导出需要具有:__declspec(dllexport)

B. 按照C语言的格式导出:extern "C"

下面是示例:

#ifdef __cplusplus

#define INTERFACE_API __declspec(dllexport)

#else

#define INTERFACE_API __declspec(dllimport)

#endif

class CGeneralInterface

{

public:

CGeneralInterface();

virtual ~CGeneralInterface();

virtual BOOL Open(CString csParam, CString &csErr) = 0;

virtual void Close() = 0;

virtual BOOL Write(LPCVOID pData, DWORD dwNumberOfBytesToWrite, CString &csErr) = 0;

virtual UINT Read(LPVOID pData, DWORD dwNumberOfBytesToRead, UINT nReadTotalTimeout, CString &csErr) = 0;

virtual CString GetParam(CString csParam, CString csStart, CString csEnd) = 0;

};
extern "C" INTERFACE_API CGeneralInterface* GeneralExport(void);

真正的实现,也是对外调用的接口:

CGeneralInterface* GeneralExport(void)

{

return (CGeneralInterface*) new CGeneralCommunication();

}

对于实现类:

#ifdef __cplusplus

extern "C" {

#endif // __cplusplus

// 此类是从 dll 导出的

class CGeneralCommunication : public CGeneralInterface

{

public:

// 实现函数

};

#ifdef __cplusplus

}

#endif // __cplusplus

相关推荐
橘颂TA19 小时前
【剑斩OFFER】算法的暴力美学——颜色分类
数据结构·c++·算法·动态规划
fish_xk20 小时前
c++基础扩展
开发语言·c++
阿沁QWQ20 小时前
C++继承
开发语言·c++
啊吧怪不啊吧20 小时前
C++之基于正倒排索引的Boost搜索引擎项目searcher部分代码及详解
c++·搜索引擎·项目
无限进步_20 小时前
C语言实现贪吃蛇游戏详解
c语言·开发语言·数据结构·c++·后端·算法·游戏
CHANG_THE_WORLD20 小时前
C++ vs Python 参数传递方式对比
java·c++·python
ULTRA??21 小时前
C++实现右折叠
开发语言·c++
handsomezqh21 小时前
洛谷U611548 助教的比拼
c++·算法
小李小李快乐不已21 小时前
图论理论基础(4)
c++·算法·图论·迭代加深
崇山峻岭之间21 小时前
C++ Prime Plus 学习笔记025
c++·笔记·学习