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

相关推荐
南郁6 小时前
007-nlohmann/json 项目应用-C++开源库108杰
c++·开源·json·nlohmann·现代c++·d2school·108杰
菠萝018 小时前
共识算法Raft系列(1)——什么是Raft?
c++·后端·算法·区块链·共识算法
海棠蚀omo8 小时前
C++笔记-C++11(一)
开发语言·c++·笔记
凌佚9 小时前
rknn优化教程(一)
c++·目标检测·性能优化
Lenyiin11 小时前
《 C++ 点滴漫谈: 四十 》文本的艺术:C++ 正则表达式的高效应用之道
c++·正则表达式·lenyiin
yxc_inspire13 小时前
基于Qt的app开发第十三天
c++·qt·app·tcp·面向对象
虾球xz14 小时前
CppCon 2015 学习:Concurrency TS Editor’s Report
开发语言·c++·学习
潇-xiao14 小时前
Qt 按钮类控件(Push Button 与 Radio Button)(1)
c++·qt
板鸭〈小号〉14 小时前
命名管道实现本地通信
开发语言·c++
YKPG15 小时前
C++学习-入门到精通【14】标准库算法
c++·学习·算法