程序代码:
AfxLoadLibrary("a.dll");其中,a.dll静态依赖于b.dll,即a.dll加载前必须加载b.dll。a.dll和b.dll均在系统的执行路径中。上述代码如果直接调用无任何问题。但如果把代码用AfxBeginThread启用新线程调用,程序则会运行到此代码处莫名其妙挂起,不再执行。补充说明:调用程序本身也静态加载了b.dll。

解决方案 »

  1.   

    b.dll是a.dll中加载的,还是需要在主程序中加载?
      

  2.   


    1.
    你的工程是动态链接到MFC运行库还是静态链接到MFC运行库的? 使用AfxLoadLibrary要求动态链接到MFC运行库.2.
    a.dll, b.dll是不是MFC扩展dll? 如果不是MFC扩展dll, 那可以试试 LoadLibrary/FreeLibray
      

  3.   

    回楼上:1、程序使用动态MFC链接库。AfxLoadLibrary在主进程中运行正常。只有在线程中运行失败,似乎有死锁现象。
    2、a.dll是MFC 规则DLL、b.dll是第三方dll,不需要mfc。
    3、LoadLibrary和FreeLibrary一样,运行到调用处死锁。
    怀疑原因,是否因为主程序已经加载了b.dll,造成线程中加载死锁?
      

  4.   


    你说的调用仅仅是指 AfxLoadLibrary 呢还是 load之后调用dll里面的函数?
      

  5.   

    仅仅是执行到AfxLoadLibrary出就不动了,潜伏……
      

  6.   

    看看那些DLLMAIN中有没有针对加载做一些初始化或其他可能导致死锁的操作另外关于Dll加载死锁的资料可以在这里找到
    http://www.microsoft.com/whdc/driver/kernel/DLL_bestprac.mspx 
      

  7.   

    可以对照一下BEST PRACTICES中对于NEVER DO的一些操作AfxBeginThread是在哪里被调用?如果是在某个DLL MAIN中的话必死锁无疑。查看开始此线程之前是否在主线程中已经acquire了loader lock
      

  8.   

    在DllMain中,看加载了,启动的时候,Process Attach中处理了什么...
      

  9.   

    可以看一下windows核心编程,里面对这个问题讲述的很清楚了,不管你加载了多少dll,
    1.当你创建新的线程的时候,都会调用每个dll的dllmain函数,
    2.并且每个dllmain函数的执行过程是同步执行的,也就是说,如果你创建线程的地方,不正确的话,就会导致dllmain由于等待事件,从而挂起。
    你可以根据这两条规则好好分析一下到底是怎么挂起了,我记得msdn上好像说过,不提倡在dllmain里面创建线程。
      

  10.   

    看看MSDN上的解释:
    Using AfxLoadLibrary and AfxFreeLibrary insures that the startup and shutdown code that executes when the extension DLL is loaded and unloaded does not corrupt the global MFC state
    是不是有接口里忘了调用AFX_MANAGE_STATE(AfxGetStaticModuleState( ))???
      

  11.   

    好久没有关注了,因为太忙。事实上,问题中的b.dll是lnnotes.dll,notes API的c++链接库。
    至于问题是否特定于notes,无法确定。不过Notes的API对多线程的支持实在不好,头疼不已。
      

  12.   

    好久没有关注了,因为太忙。事实上,问题中的b.dll是lnnotes.dll,notes API的c++链接库。
    至于问题是否特定于notes,无法确定。不过Notes的API对多线程的支持实在不好,头疼不已。
      

  13.   

    This maybe a typical deadlock problem involves LdrLoaderLock. Open you exe in WinDBG and reproduce the problem. Type !locks in the WinDBG command line, it shows all the locks and their state in your process. Find out which thread is waiting for LdrLoaderLock and who is holding it. Find out what the thread holding LdrLoaderLock is doing. It is probably waiting for another lock. Find out which thread is holding the other lock and what it is doing. Finally you will reach your own thread which is calling AfxLoadLibrary. You’ll have to solve the problem by breaking up the loop.