当前位置:网站首页>调用DLL开启线程的问题
调用DLL开启线程的问题
2022-07-26 09:25:00 【asiwxy】
错误的编写方式:(注意用感叹号夹起来的两行)在 ::FreeLibrary(hPro);这一行代码执行之后,dll里面的分配的内存空间就会全部被释放掉,所以会报“帧不在模块之中”,“内存访问错误”之类的错误。
void CMFCApplication2Dlg::OnBnClickedOk()
{
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
HINSTANCE hPro = ::LoadLibrary("MFCLibrary1.dll");//加载一个自己写的DLL,提供了一
//getCFindFile用于获取一个类指
//针;
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
if (hPro == NULL)
{
return ;
}
else
{
typedef MyCFindFile* (*MENU_EXECUTE)();
MENU_EXECUTE getCFindFile = NULL;
getCFindFile = (MENU_EXECUTE)::GetProcAddress(hPro, "getCFindFile");//MenuExecute 函数名字
if (getCFindFile)
{
MyCFindFile * pItem = getCFindFile();
CString s;
GetDlgItemText(IDC_EDIT4,s);
s.Format(_T("%s"), s);
std::string strStr;
strStr = s.GetBuffer(0);
HWND hdlg = GetSafeHwnd();
pItem->funcFindFile(strStr, hdlg, 2);
//pItem->m_hMainDlg = GetSafeHwnd();//把当前主对话框的窗口句柄传过去,这样就可以在线程函数中使用
//m_ResultList.DeleteAllItems();//清空上一次执行完之后的信息
//std::string strStr;
//strStr = pItem->m_PathFind.GetBuffer(0);
//funcFindFile(strStr, pItem->m_hMainDlg);
}
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
::FreeLibrary(hPro);
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
}
return;
}正确的写法:
1,将HINSTANCE hPro;添加到类成员变量之中
2,将FreeLibrary(hPro);函数放到MFC退出按钮里面,反正要保证在使用完hpro之前不要释放掉,也可以直接用静态加载
边栏推荐
- Does volatile rely on the MESI protocol to solve the visibility problem? (next)
- Redis principle and usage - installation and distributed configuration
- 滑动窗口、双指针、单调队列、单调栈
- JVM触发minor gc的条件
- Byte buffer stream & character stream explanation
- Pat grade a A1034 head of a gang
- 2022 mobile crane driver test question simulation test question bank simulation test platform operation
- 暑假第四周
- js中树与数组的相互转化(树的子节点若为空隐藏children字段)
- Polynomial open root
猜你喜欢
![[online problem] timeout waiting for connection from pool problem troubleshooting](/img/f0/7e8444ed7d0921b98d5e998e274bc8.png)
[online problem] timeout waiting for connection from pool problem troubleshooting

Your login IP is not within the login mask configured by the administrator

微信小程序学习笔记1

使用openLayer画箭头

ZXing简化版,转载

语音聊天app源码——钠斯直播系统源码

Exception handling mechanism II

js在控制台输出菱形

异常处理机制二

Paper notes: knowledge map kgat (unfinished temporary storage)
随机推荐
吴恩达机器学习之线性回归
Object 的Wait Notify NotifyAll 源码解析
2022 mobile crane driver test question simulation test question bank simulation test platform operation
I'm faded
STM32+MFRC522完成IC卡号读取、密码修改、数据读写
Sending and receiving of C serialport
Elastic APM installation and use
【Mysql】Mysql锁详解(三)
暑假末尾学习笔记
asp.net 使用redis缓存(二)
jvm命令归纳
asp.net 使用redis缓存
Fiddler下载安装
Server memory failure prediction can actually do this!
csdn空格用什么表示
[online problem] timeout waiting for connection from pool problem troubleshooting
Fiddler抓包工具之移动端抓包
phpexcel导出emoji符号报错
【线上问题】Timeout waiting for connection from pool 问题排查
opencv图像处理