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

相关推荐
乌萨奇也要立志学C++8 分钟前
【C++详解】STL-list模拟实现(深度剖析list迭代器,类模板未实例化取嵌套类型问题)
c++·list
闻缺陷则喜何志丹27 分钟前
【前缀和 BFS 并集查找】P3127 [USACO15OPEN] Trapped in the Haybales G|省选-
数据结构·c++·前缀和·宽度优先·洛谷·并集查找
序属秋秋秋2 小时前
《C++初阶之内存管理》【内存分布 + operator new/delete + 定位new】
开发语言·c++·笔记·学习
十秒耿直拆包选手9 小时前
Qt:主窗体(QMainwindow)初始化注意事项
c++·qt
霖0011 小时前
C++学习笔记三
运维·开发语言·c++·笔记·学习·fpga开发
mit6.82411 小时前
[shad-PS4] Vulkan渲染器 | 着色器_重新编译器 | SPIR-V 格式
c++·游戏引擎·ps4
tan77º12 小时前
【Linux网络编程】Socket - TCP
linux·网络·c++·tcp/ip
Mike_Zhang13 小时前
C++使用WinHTTP访问http/https服务
c++
CHANG_THE_WORLD13 小时前
「macOS 系统字体收集器 (C++17 实现)」
开发语言·c++·macos
GiraKoo14 小时前
【GiraKoo】Breakpad 崩溃分析系统
c++