有人遇到过在freelibrary时阻塞的情况吗?

解决方案 »

  1.   

    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在占用,是否释放也需要很长时间?
      

  2.   

    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);
      

  3.   

    谢了,这里是个问题,不过阻塞应该不是这里的问题,因为temp基本不会返回1,还有一个问题,这是个线程函数,如果hinstance是个全局变量,调用MakeConnectionString成功,调用_DataVerify失败,唉,dll不是自己写的就是很麻烦
      

  4.   

    不会是线程死锁的问题,就算是只启动一个线程也不能释放DLL资源,这个问题好怪,好几天了也解决不了,如果没有人知道,只好通知DELPHI部门优化程序了。
      

  5.   

    注意。。在DllMain函数中 绝不要做过多的事情。。
    否则会死锁 详见 windows 核心编程 20 - 22章