FIX: DllMain Throws Unhandled Exception with DLL_THREAD_DETACH (256056)



The information in this article applies to:

  • The Microsoft Foundation Classes (MFC), when used with:
    • Microsoft Visual C++, 32-bit Editions 5.0
    • Microsoft Visual C++, 32-bit Editions 6.0

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.

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.

Modification Type:MajorLast Reviewed:9/13/2006
Keywords:kbArchitecture kbbug kbDLL kbExceptHandling kbfix kbVS600sp4fix kbVS600sp5fix KB256056