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
- 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++ 6.0 Standard Edition
- Microsoft Visual C++ .NET 2002 Standard Edition
- Microsoft Visual C++ .NET 2003 Standard Edition
This article was previously published under Q158552
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.
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
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
- 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.
STATUS
This
behavior is by design.
REFERENCES
For more information, click the following article number to view the article in the Microsoft Knowledge Base:
126630
Resource sections are read-only
Keywords: kbtshoot kbcode kbprb kbuidesign KB158552