当前位置:网站首页>调用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之前不要释放掉,也可以直接用静态加载
边栏推荐
- Voice chat app source code - Nath live broadcast system source code
- 838. Heap sorting
- 微信小程序学习笔记2
- [arkit, realitykit] turn pictures into 3D models
- Li Mu D2L (IV) -- softmax regression
- 微信小程序学习笔记1
- 839. 模拟堆
- 2022 chemical automation control instrument operation certificate test question simulation test platform operation
- nodejs中mysql的使用
- 大二上第三周学习笔记
猜你喜欢

arc-gis基础操作3

Personality test system V1.0

volatile 靠的是MESI协议解决可见性问题?(下)
![[MySQL] detailed explanation of MySQL lock (III)](/img/3c/c6b5aa5693e6e7b5730a286d988c82.png)
[MySQL] detailed explanation of MySQL lock (III)

登录模块用例编写

NTT (fast number theory transformation) polynomial inverse 1500 word analysis

Polynomial open root

2022 chemical automation control instrument operation certificate test question simulation test platform operation

搜索模块用例编写

asp.net 使用redis缓存
随机推荐
2022 chemical automation control instrument operation certificate test question simulation test platform operation
微信小程序学习笔记2
Go intelligent robot alpha dog, alpha dog robot go
2022 Shanghai safety officer C certificate examination questions and mock examination
【线上死锁分析】由index_merge引发的死锁事件
【线上问题】Timeout waiting for connection from pool 问题排查
LeetCode三数之和问题
arcgis的基本使用1
Voice chat app source code - Nath live broadcast system source code
省政府召开全省高温天气安全防范工作电视电话会议
nodejs中mysql的使用
Paper notes: knowledge map kgat (unfinished temporary storage)
arc-gis基础操作3
TabbarController的封装
volatile 靠的是MESI协议解决可见性问题?(下)
Tornado multi process service
暑假第四周
[MySQL] detailed explanation of MySQL lock (III)
大二上第三周学习笔记
keepalived 实现mysql自动故障切换