You are currently offline, waiting for your internet to reconnect

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

This article was previously published under Q158552
This article has been archived. It is offered "as is" and will no longer be updated.
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.
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
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:
  • 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.
  • 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.
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.
This behavior is by design.

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);   }				
For more information, click the following article number to view the article in the Microsoft Knowledge Base:
126630 Resource sections are read-only

Article ID: 158552 - Last Review: 12/04/2015 15:41:40 - Revision: 4.1

Microsoft Foundation Class Library 4.2

  • kbnosurvey kbarchive kbtshoot kbuidesign kbprb kbcode KB158552