Microsoft KB Archive/143071

= FIX: CPropertySheet::DoModal or Create Causes an Exception =

Article ID: 143071

Article Last Modified on 11/21/2006

-

APPLIES TO


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

-



This article was previously published under Q143071



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  (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 " 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.

