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

相关推荐
xiaolang_8616_wjl7 小时前
c++文字游戏_闯关打怪2.0(开源)
开发语言·c++·开源
夜月yeyue7 小时前
设计模式分析
linux·c++·stm32·单片机·嵌入式硬件
无小道7 小时前
c++-引用(包括完美转发,移动构造,万能引用)
c语言·开发语言·汇编·c++
FirstFrost --sy9 小时前
数据结构之二叉树
c语言·数据结构·c++·算法·链表·深度优先·广度优先
Tanecious.10 小时前
C++--map和set的使用
开发语言·c++
Yingye Zhu(HPXXZYY)10 小时前
Codeforces 2021 C Those Who Are With Us
数据结构·c++·算法
liulilittle11 小时前
LinkedList 链表数据结构实现 (OPENPPP2)
开发语言·数据结构·c++·链表
无聊的小坏坏11 小时前
三种方法详解最长回文子串问题
c++·算法·回文串
山河木马11 小时前
前端学习C++之:.h(.hpp)与.cpp文件
前端·javascript·c++
2401_8919573111 小时前
list的一些特性(C++)
开发语言·c++