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

Article translations Article translations
Article ID: 158552 - View products that this article applies to.
This article was previously published under Q158552
Expand all | Collapse all

On This Page


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 *****/ 

   /***** this code is OK *****/ 
       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: November 21, 2006 - Revision: 4.1
  • 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
    • Microsoft Visual C++ 5.0 Enterprise Edition
    • Microsoft Visual C++ 5.0 Professional Edition
    • Microsoft Visual C++ 6.0 Enterprise Edition
    • Microsoft Visual C++ 6.0 Professional Edition
    • Microsoft Visual C++, 32-bit Learning Edition 6.0
    • Microsoft Visual C++ .NET 2002 Standard Edition
    • Microsoft Visual C++ .NET 2003 Standard Edition
kbtshoot kbuidesign kbprb kbcode KB158552

Give Feedback


Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from