Microsoft KB Archive/256056

= FIX: DllMain Throws Unhandled Exception with DLL_THREAD_DETACH =

Article ID: 256056

Article Last Modified on 11/21/2006

-

APPLIES TO

 Microsoft Foundation Class Library 4.2, when used with:  Microsoft Visual C++ 5.0 Standard Edition

 Microsoft Visual C++ 6.0 Service Pack 5 

-



This article was previously published under Q256056



SYMPTOMS
The DllMain code in MFC throws an unhandled exception if the system runs out of memory during the DLL_THREAD_DETACH operation. This applies to regular DLLs, either statically or dynamically linked to MFC and also to any module that uses the MFC Dlls (MFC42[U].dll, MFC42[U]D.dll, MFCO42[U]D.dll, MFCN42[U]D.dll, MFCD42[U]D.dll).



CAUSE
MFC, in the DllMain code, during the DLL_THREAD_DETACH operation, cleans up the thread local data that it maintains. In the process, it creates some new temporary objects. If the memory allocation fails during this process due to low memory conditions in the system, it throws a memory exception. Because this exception never gets caught, you receive an unhandled exception from the process.



RESOLUTION
The Mfc42.dll and Mfc42u.dll files that shipped with Windows 2000 have this fix incorporated.

<div class="status_section">

STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article. This bug was corrected in the latest service pack for Visual Studio 6.0.

Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.

<div class="references_section">