Microsoft KB Archive/158552

= You receive a "0xC0000005: Access Violation" error message when you call the CPropertySheet::DoModal method or the Create method in Visual C++ =

Article ID: 158552

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

 Microsoft Visual C++ 4.1 Subscription

 Microsoft Visual C++ 4.2 Enterprise Edition

 Microsoft Visual C++ 4.2 Professional Edition</li></ul>

 Microsoft Visual C++ 5.0 Enterprise Edition</li></ul>

 Microsoft Visual C++ 5.0 Professional Edition</li></ul>

 Microsoft Visual C++ 6.0 Enterprise Edition</li></ul>

 Microsoft Visual C++ 6.0 Professional Edition</li></ul>

 Microsoft Visual C++ 6.0 Standard Edition</li></ul>

 Microsoft Visual C++ .NET 2002 Standard Edition</li></ul>

 Microsoft Visual C++ .NET 2003 Standard Edition</li></ul> </li></ul>

-

<div class="notice_section">

This article was previously published under Q158552

<div class="symptoms_section">

SYMPTOMS
When you call CPropertySheet::DoModal or CPropertySheet::Create, an exception might occur. The Output window displays the following message:

First-chance exception in <program.exe> (Comctl32.dll): 0xC0000005: Access Violation.

The exception is expected and is handled by the operating system. This will only occur the first time you call either of these methods and subsequent calls will not generate this first-chance exception.

<div class="cause_section">

CAUSE
The CommCtl32.dll tries to modify the resources for the pages. Because the resources are typically in read-only sections, this throws a first-chance exception that will be caught by the operating system. The operating system handles this exception and makes the resources writeable and then everything completes normally. Because the resources are now writeable, all subsequent calls complete without this first-chance exception

<div class="resolution_section">

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

To prevent the exception, use one of the following methods:   Method 1: Make the resources read/write. You can do this by adding a linker setting as follows: /SECTION:.rsrc,rw </li> <li>Method 2: Change the font of the pages so they are not MS Sans Serif. MFC checks the dialog template font for the page. If it is not MS Sans Serif, MFC makes a copy of the resource in read/write memory, and then modifies the font and passes this to the C mCtl32.dll. When the DLL writes to the template for the page, it is writing to read/write memory. Therfore, an exception is not thrown.</li> <li>Method 3: Do not have the call for creating the property sheet in a try/catch(...) block. Instead, catch particular exceptions in the catch block.</li></ul>

If the property sheet is part of an OLE Automation Server that can be invoked through a method of the server, make the resources read/write by using one of the first two methods because OLE catches the exception.

Note When you change the resources to Read/Write, the resources might be written to a page file.

<div class="status_section">

STATUS
This behavior is by design.

<div class="moreinformation_section">

Sample Code
/* 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); }

<div class="references_section">