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 小时前
C++ 后端开发面试题整理
java·c++·面试
xlq223226 小时前
全面复习1
c++
Dylan的码园6 小时前
求平均成绩 矩阵数据处理 【循环处理 二维数组】
c++·线性代数·矩阵
All for pursuit.7 小时前
【回溯-2】22.括号生成
数据结构·c++·算法·leetcode
longlongzihan7 小时前
LeetCode 1004.最大连续1的个数III 滑动窗口及动态规划题解
c++·算法·leetcode·dp·滑动窗口
朝朝辞暮i7 小时前
C++ 第 22 课:const —— 不允许随便修改的数据
开发语言·c++·算法
蒸蒸yyyyzwd8 小时前
力扣二分总结-lowerbound
c++
ShineWinsu8 小时前
对于Redis:List类型的解析
数据库·c++·redis·链表·缓存·面试·list
小师兄吃牛肉9 小时前
C++ 与 Lua 的协程交互:从原理到实战
c++·lua·交互