当前位置:网站首页>动态库之间回调函数使用
动态库之间回调函数使用
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
边栏推荐
- JS语法使用
- Chapter 12 贝叶斯网络
- 浅谈自动采集程序及入库
- 彩绘漂亮MM集
- SVG Star Wars Style Toggle Toggle Button
- 真正爱你的女人是这样的
- C语言制作-QQ聊天室
- Basic introduction of stack and queue and C language implementation of functions such as creation, destruction, entry and exit, counting the number of elements, viewing elements, etc., as well as stac
- egg框架
- 请问my sql如何把两个表的内容集合在一起啊?
猜你喜欢
关于MP3文件中找不到TAG标签的问题
SVG big fish eat small fish animation js special effects
MySQL 数据库 报错 The server quit without updating PID file (/var/lib/mysql/localhost.localdomain.pid)
复现一次循环和两次循环
TensorFlow installation steps
Ethernet Principle
餐饮大单品「真香」,却没有穿透周期的能力
ps怎么把图片变清晰,自学ps软件photoshop2022,简单快速用ps让照片更清晰更有质感
Jmeter永久设置中文界面
数据源对象管理Druid和c3p0
随机推荐
行业应用软件项目经理三步曲
[Untitled] Long-term recruitment of hardware engineers-Shenzhen Baoan
Redis实现分布式锁-原理-问题详解
作为一个男人必须明白的22个道理
DataFrame insert row and column at specified position
[Structure internal power practice] Structure memory alignment (1)
window.open 全屏展示
Ethernet Principle
复现一次循环和两次循环
吴恩达深度学习deeplearning.ai——第一门课:神经网络与深度学习——第二节:神经网络基础(下)
Controller-----controller
MySQL 数据库 报错 The server quit without updating PID file (/var/lib/mysql/localhost.localdomain.pid)
Beautifully painted MM set
手机上流行的各类谜语
爱情是一部忧伤的乐曲
JVM运行流程,运行时数据区,类加载,垃圾回收,JMM解析
网页直接访问链接不让安全中心拦截
SVG big fish eat small fish animation js special effects
嵌入式系统:基本定时器
随机码的生成