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.
看看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( ))???