微软官方有解释:
PRB: Cannot Create an MFC Thread During DLL Startup
SYMPTOMS
An MFC DLL that creates a new MFC thread during startup hangs when loaded by an application. This includes whenever a thread is created by calling AfxBeginThread or CWinThread::CreateThread inside:
the InitInstance of a CWinApp-derived object in a Regular DLL.
a supplied DllMain or RawDllMain function in a Regular DLL.
a supplied DllMain or RawDllMain function in an Extension DLL.
CAUSE
For Regular DLLs, which have a CWinApp-derived object, the CWinApp::InitInstance override is called from MFC's supplied DllMain when a process is attaching to the DLL. That is, DllMain is entered with a Reason For Call of DLL_PROCESS_ATTACH, and in handling this, MFC calls in to InitInstance before cleaning up and leaving DllMain.
For Extension DLLs, the startup of the DLL is
SYMPTOMS
An MFC DLL that creates a new MFC thread during startup hangs when loaded by an application. This includes whenever a thread is created by calling AfxBeginThread or CWinThread::CreateThread inside:
the InitInstance of a CWinApp-derived object in a Regular DLL.
a supplied DllMain or RawDllMain function in a Regular DLL.
a supplied DllMain or RawDllMain function in an Extension DLL.
CAUSE
For Regular DLLs, which have a CWinApp-derived object, the CWinApp::InitInstance override is called from MFC's supplied DllMain when a process is attaching to the DLL. That is, DllMain is entered with a Reason For Call of DLL_PROCESS_ATTACH, and in handling this, MFC calls in to InitInstance before cleaning up and leaving DllMain.
For Extension DLLs, the startup of the DLL is