当前位置:网站首页>动态库之间回调函数使用
动态库之间回调函数使用
2022-08-05 08:13:00 【开心大爆炸】
转自: 动态库之间回调函数使用 - 出来打酱油 - 博客园 (cnblogs.com)
https://www.cnblogs.com/huyupei/p/8298621.html
在底层dll实现
接口.h文件
typedef interfaceBase* (lpObjCreate)();
class interfaceBase
{
virtual setcallback(callbackBase* callback){};
}
class callbackBase
{
virtual void callback(){};
}.cpp文件
extern "C" __declspec(dllexport) interfaceBase* CreateObjCreate();
CLibMQTT* CreateObjCreate()
{
return interRealize ::Instance();
}底层dll实现
class interRealize :public interfaceBase
{
//单例不多写
setcallback(callbackBase* callback){m_callback = callback;};
callbackBase* getcallback(){return m_callback;};
private:
callbackBase* m_callback;
static interRealize * m_instance;
}上层dll实现
class callbackDeal : public callbackBase
{
void callback(){ int i = 0;};
}
void main
{
HINSTANCE hDllUCLib = LoadLibrary(L".\\lib*.dll");
interfaceBase*pFunc = (interfaceBase*)GetProcAddress(hDllUCLib, "CreateObjCreate");
m_libMQTTBase = pFunc();
m_libMQTTBase ->setcallback(new callbackDeal );//如此callback就是实现callbackDeal 的方法;
}//这样数据交互就从下层dll转移到上层dll中,MFC的话,在根据回调具体函数 发消息到主窗体;如此将下层代码和上层区分开
}
//该处只是简单描述;并没有贴代码;该功能将单例和多态结合使用,因此将该方法记录下来
//另外在底层dll实现class的 static函数(回调函数)中 可以使用 interRealize ::Instance()->getcallback();来获取上层callbackDeal 的指针,将底层的回调函数的参数带出;
查看: c++ 在类中写回调函数
c++ 在类中写回调函数_BBinChina的博客-CSDN博客_类中回调函数
https://blog.csdn.net/BBinChina/article/details/45098183
边栏推荐
- unity urp 渲染管线顶点偏移的实现
- 行业应用软件项目经理三步曲
- How to make pictures clear in ps, self-study ps software photoshop2022, simple and fast use ps to make photos clearer and more textured
- 软件系统测试和验收测试有什么联系与区别?专业软件测试方案推荐
- Constellation ideal lover
- Data source object management Druid and c3p0
- P1160 队列安排
- [Structure internal power practice] Structure memory alignment (1)
- Support touch screen slider carousel plugin
- 8.4模拟赛总结
猜你喜欢

uniapp time component encapsulates year-month-day-hour-minute-second

苹果官网商店新上架Mophie系列Powerstation Pro、GaN充电头等产品

MySQL database error The server quit without updating PID file (/var/lib/mysql/localhost.localdomain.pid)

Embedded Systems: Basic Timers

What is a good movie to watch on Qixi Festival?Crawl movie ratings and save to csv file

Redis cache and existing problems--cache penetration, cache avalanche, cache breakdown and solutions

网页直接访问链接不让安全中心拦截
![[Structural Internal Power Cultivation] The Mystery of Enumeration and Union (3)](/img/39/d20f45ccc86ebc4e5aebc8e4d0115f.png)
[Structural Internal Power Cultivation] The Mystery of Enumeration and Union (3)

Chapter 12 Bayesian Networks

【结构体内功修炼】结构体内存对齐(一)
随机推荐
监听浏览器刷新操作
基于 Docker 快速使用远程(云)数据库
链表专项之环形链表
What is a good movie to watch on Qixi Festival?Crawl movie ratings and save to csv file
达梦数据库大表添加字段
【结构体内功修炼】结构体内存对齐(一)
吴恩达深度学习deeplearning.ai——第一门课:神经网络与深度学习——第二节:神经网络基础(下)
长期招聘嵌入式开发-深圳宝安
[转帖]嫁人一定要嫁工资至少比你高3571.4元的男士
Constellation ideal lover
D2--FPGA SPI接口通信2022-08-03
在原有数据库基础上执行sql文件有则跳过没有则添加如何实现?
控制器-----controller
egg框架
谷歌零碎笔记之MVCC(草稿)
Chapter3、色调映射
512色色谱图
数据源对象管理Druid和c3p0
TensorFlow installation steps
Chapter 12 Bayesian Networks