Modifying property sheet templates on Win95

Download the source

This code is written to fix the bug in CPropertySheet::DoModal() or CPropertySheet::Create() as described in MSKB article ID: Q158552.

The description of the bug:

(This bug is present for comctl32.dll version <4.70 and Windows95.) When a property sheet displays its property pages, it has to modify their templates. It tries to write into the memory; that works under Win32s (because the resources are writable) and it works under WinNT (because BeginResourceUpdate exists) but it fails under Win95 and raises an Access Violation. If you are not working with exceptions (try/catch(...), __try/__except, _set_se_translator) everything's OK - the OS gets the exception, unlocks the resources (or copies them to writable memory). However, if you're trying to be a good programmer and you add some code to your app to catch OS exceptions you are in a deep trouble.

The suggested fix #1 in the KB article (make the .rsrc section writable) is OK but error-prone. It is not a very aestheticly pleasing solution either.

The suggested fix #2 in the KB article is nonsense - or I didn't understand correctly what it says.

The suggested fix #3 is unusable if you want to have __try/__except. Also, you can't catch access violations when the property sheet is active.

In this article, I offer another solution: I created a CSafePropertyPage class based on CPropertyPage. The one and only difference is that this modified property page uses a (potentially writable) copy of a dialog template instead of just using resource ID. It uses undocumented MFC class CDialogTemplate (defined in afxpriv.h) but you may look up the source code of CDialogTemplate and supply your own CDialogTemplate::Load if you desperately want to keep the documented/undocumented paradigm of MFC.

Attached are the source files - just include the header where you need it and use CSafePropertyPage anywhere you'd use CPropertyPage.

Last updated: 30 June 1998



Comments

  • Modifying Property Sheet Templates on Win95

    Posted by Legacy on 02/11/2003 12:00am

    Originally posted by: Gerd Neumann

    Dear Petr Novotny,

    this was my rescue !!

    Thanks

    Reply
  • CPropertyPage::DoModal

    Posted by Legacy on 07/14/2002 12:00am

    Originally posted by: Daedalus

    I've experienced the problem you mentioned with the DoModal member function of MFC's CPropertySheet class. You suggested that you've created a class CSafePropertySheet, however I can't seem to find the code.

    Would you mind pointing me in the right direction? Meanwhile, I'll try looking through the MFC code that you suggested.

    Thanks.

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: August 20, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT When you look at natural user interfaces as a developer, it isn't just fun and games. There are some very serious, real-world usage models of how things can help make the world a better place – things like Intel® RealSense™ technology. Check out this upcoming eSeminar and join the panel of experts, both from inside and outside of Intel, as they discuss how natural user interfaces will likely be getting adopted in a wide variety …

  • Live Event Date: August 19, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT You deployed your app with the Bluemix PaaS and it's gaining some serious traction, so it's time to make some tweaks. Did you design your application in a way that it can scale in the cloud? Were you even thinking about the cloud when you built the app? If not, chances are your app is going to break. Check out this upcoming eSeminar to learn various techniques for designing applications that will scale successfully in Bluemix, for the …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds