FIX: CPropertySheet::DoModal() or Create() Causes an Exception

Last reviewed: February 17, 1998
Article ID: Q143071
The information in this article applies to:
  • The Microsoft Foundation Classes (MFC), included with: - Microsoft Visual C++, 32-bit Edition, version 4.0

SYMPTOMS

Under Windows 95, calling CPropertySheet::DoModal() or CPropertySheet::Create() may cause an exception. The output window displays a message saying "First-chance exception in <program.exe> (COMCTL32.DLL): 0xC0000005: Access Violation."

There is a second related problem. If the call to DoModal() or Create() is inside a try/catch(...) block, you will get an error saying "This program has performed an illegal operation..." If you click the Details button, it will say "<PROGRAM> caused a stack fault in module MSVCR40D.DLL at..."

CAUSE

Before a property page is created, it changes the style of the dialog resource to the required style. Because resources are generally read-only, this causes an exception.

The stack fault problem is caused by a bug in the C++ exception handling routine. When the exception occurs and it is trapped by a try/catch(...) block, it is not forwarded on to the operating system. This leads to unpredictable results.

RESOLUTION

The first-chance exception can be ignored because it is safely handled by the operating system.

A workaround for the stack fault problem is to use C++ exception handling with specific exception types or use structured exception handling where the access violation exception is passed through to the operating system.

Sample Code to Demonstrate Workaround to Stack Fault Problem

   /* Compile options needed:  default
   */

   /***** this code will cause unpredictable results *****/
   try
   {
       sheet.DoModal();
   }
   catch(...)
   {
   }

   /***** this code is OK *****/
   try
   {
       if (0 == sheet.DoModal())
           throw "DoModal() failed!";
   }
   catch(char * str)
   {
       TRACE ("Exception thrown: %s\n", str);
   }

STATUS

This problem was corrected in Visual C++ version 5.0 and with Comctl32.dll included with Internet Explorer 3.2 and later.

REFERENCES

This is also documented in the Vcread.wri readme file.


Additional query words: 4.00
Keywords : MfcUI kbcode
Technology : kbmfc
Version : win95:4.0
Platform : Win95
Issue type : kbprb
Solution Type : kbfix


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: February 17, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.