loadlibrary后,调用DLL中函数执行数据库校验,校验时间若短,dll可以free,若长,程序在freelibrary处阻塞了!!! 有人遇到过在freelibrary时阻塞的情况吗? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 typedef int(_stdcall *DATAVERIFY)(char*, char*, char*, char*, int, int, int); typedef char*(_stdcall *MAKECONNECTIONSTRING)(char*, char*, char*); DATAVERIFY _DataVerify = NULL; MAKECONNECTIONSTRING MakeConnectionString = NULL; HINSTANCE hinstance = NULL; hinstance = ::LoadLibrary("DataVerify.dll"); if(hinstance){ MakeConnectionString = (MAKECONNECTIONSTRING)GetProcAddress(hinstance,"MakeConnectionString"); if(MakeConnectionString){ cRn = MakeConnectionString(pThis->m_pSevInfo->strUser.GetBuffer(pThis->m_pSevInfo->strUser.GetLength()), pThis->m_pSevInfo->strPsw.GetBuffer(pThis->m_pSevInfo->strPsw.GetLength()), pThis->m_pSevInfo->strConstr.GetBuffer(pThis->m_pSevInfo->strConstr.GetLength())); } CString str = cRn;// ::AfxMessageBox(str); _DataVerify = (DATAVERIFY)GetProcAddress(hinstance,"_DataVerify"); if(_DataVerify){ temp = _DataVerify(str.GetBuffer(0), pThis->m_pSevInfo->strAdwdm.GetBuffer(pThis->m_pSevInfo->strAdwdm.GetLength()), "2004", "10", 1, 0, 0); if(temp == 1){ CString str; str.Format("%d%d", temp, pThis->m_nConstr);// ::AfxMessageBox(str); ::FreeLibrary(hinstance); SetEvent(g_checkhEvent); return 0; } else{ } } }// GetError(); int nfree = ::FreeLibrary(hinstance);在最后一句代码阻塞,程序几乎死掉(执行DataVerify函数1个小时,释放也放了一个小时没出来),一查任务管理器:使用内存55M, 线程数211, 句柄数2905,这个大的资源几乎都是那个DLL在占用,是否释放也需要很长时间? hinstance = ::LoadLibrary("DataVerify.dll");if(hinstance){ MakeConnectionString = (MAKECONNECTIONSTRING)GetProcAddress(hinstance,"MakeConnectionString"); if(MakeConnectionString) { cRn = MakeConnectionString(pThis->m_pSevInfo->strUser.GetBuffer(pThis->m_pSevInfo->strUser.GetLength()), pThis->m_pSevInfo->strPsw.GetBuffer(pThis->m_pSevInfo->strPsw.GetLength()), pThis->m_pSevInfo->strConstr.GetBuffer(pThis->m_pSevInfo->strConstr.GetLength())); } CString str = cRn;// ::AfxMessageBox(str); _DataVerify = (DATAVERIFY)GetProcAddress(hinstance,"_DataVerify"); if(_DataVerify) { temp = _DataVerify(str.GetBuffer(0), pThis->m_pSevInfo->strAdwdm.GetBuffer(pThis->m_pSevInfo->strAdwdm.GetLength()), "2004", "10", 1, 0, 0); if(temp == 1) { CString str; str.Format("%d%d", temp, pThis->m_nConstr);// ::AfxMessageBox(str); ::FreeLibrary(hinstance); //,OK SetEvent(g_checkhEvent); return 0; } else { ::FreeLibrary(hinstance); //add by wenxy1 } } }// GetError();//error!!!// int nfree = ::FreeLibrary(hinstance); 谢了,这里是个问题,不过阻塞应该不是这里的问题,因为temp基本不会返回1,还有一个问题,这是个线程函数,如果hinstance是个全局变量,调用MakeConnectionString成功,调用_DataVerify失败,唉,dll不是自己写的就是很麻烦 不会是线程死锁的问题,就算是只启动一个线程也不能释放DLL资源,这个问题好怪,好几天了也解决不了,如果没有人知道,只好通知DELPHI部门优化程序了。 注意。。在DllMain函数中 绝不要做过多的事情。。否则会死锁 详见 windows 核心编程 20 - 22章 求P2P协议方面的学习资料 VC/MFC 大家来看看这个怎样才能实现这个界面的编译 VC++中可不可以通过连接别的机器上的数据库,对该机器上的数据库进行访问和管理? 在线等,跪求COM本质论的配套原码! MFC利用opencv控件显示视频问题 为何不能取得DC上面的位图数据 return的作用! 我现在作的“打开文件对话框”一次打开三五个文件还可以,但是一次打开几十个就出问题,要修改哪个参数? 关于聚合的问题 谁知道在vc中如何调用com组件???急 请教:IMoniker接口如何使用? 求一个VC用IXMLDOMDocument2操作XML的范例
typedef char*(_stdcall *MAKECONNECTIONSTRING)(char*, char*, char*);
DATAVERIFY _DataVerify = NULL;
MAKECONNECTIONSTRING MakeConnectionString = NULL;
HINSTANCE hinstance = NULL;
hinstance = ::LoadLibrary("DataVerify.dll");
if(hinstance){
MakeConnectionString = (MAKECONNECTIONSTRING)GetProcAddress(hinstance,"MakeConnectionString");
if(MakeConnectionString){
cRn = MakeConnectionString(pThis->m_pSevInfo->strUser.GetBuffer(pThis->m_pSevInfo->strUser.GetLength()),
pThis->m_pSevInfo->strPsw.GetBuffer(pThis->m_pSevInfo->strPsw.GetLength()),
pThis->m_pSevInfo->strConstr.GetBuffer(pThis->m_pSevInfo->strConstr.GetLength()));
}
CString str = cRn;
// ::AfxMessageBox(str);
_DataVerify = (DATAVERIFY)GetProcAddress(hinstance,"_DataVerify");
if(_DataVerify){
temp = _DataVerify(str.GetBuffer(0), pThis->m_pSevInfo->strAdwdm.GetBuffer(pThis->m_pSevInfo->strAdwdm.GetLength()),
"2004", "10", 1, 0, 0);
if(temp == 1){
CString str;
str.Format("%d%d", temp, pThis->m_nConstr);
// ::AfxMessageBox(str);
::FreeLibrary(hinstance);
SetEvent(g_checkhEvent);
return 0;
}
else{
}
}
}
// GetError();
int nfree = ::FreeLibrary(hinstance);
在最后一句代码阻塞,程序几乎死掉(执行DataVerify函数1个小时,释放也放了一个小时没出来),一查任务管理器:使用内存55M, 线程数211, 句柄数2905,这个大的资源几乎都是那个DLL在占用,是否释放也需要很长时间?
if(hinstance)
{
MakeConnectionString = (MAKECONNECTIONSTRING)GetProcAddress(hinstance,"MakeConnectionString");
if(MakeConnectionString)
{
cRn = MakeConnectionString(pThis->m_pSevInfo->strUser.GetBuffer(pThis->m_pSevInfo->strUser.GetLength()),
pThis->m_pSevInfo->strPsw.GetBuffer(pThis->m_pSevInfo->strPsw.GetLength()),
pThis->m_pSevInfo->strConstr.GetBuffer(pThis->m_pSevInfo->strConstr.GetLength()));
}
CString str = cRn;
// ::AfxMessageBox(str);
_DataVerify = (DATAVERIFY)GetProcAddress(hinstance,"_DataVerify");
if(_DataVerify)
{
temp = _DataVerify(str.GetBuffer(0), pThis->m_pSevInfo->strAdwdm.GetBuffer(pThis->m_pSevInfo->strAdwdm.GetLength()),
"2004", "10", 1, 0, 0);
if(temp == 1)
{
CString str;
str.Format("%d%d", temp, pThis->m_nConstr);
// ::AfxMessageBox(str);
::FreeLibrary(hinstance); //,OK
SetEvent(g_checkhEvent);
return 0;
}
else
{
::FreeLibrary(hinstance); //add by wenxy1
}
}
}
// GetError();//error!!!
// int nfree = ::FreeLibrary(hinstance);
否则会死锁 详见 windows 核心编程 20 - 22章