Microsoft KB Archive/309554

= BUG: MMC - Access Violation with Multiple Property Pages =

Article ID: 309554

Article Last Modified on 3/20/2004

-

APPLIES TO


 * Microsoft Management Console 2.0
 * Microsoft Management Console 1.0
 * Microsoft Management Console 1.1
 * Microsoft Management Console 1.2

-



This article was previously published under Q309554



SYMPTOMS
Microsoft Management Console (MMC) may experience an access violation (AV) when two property sheets are displayed at the same time and the user switches back and forth between pages on the two sheets. This can happen when two snap-ins are implemented in the same dynamic link library (DLL) and both snap-ins are displaying property sheets with pages derived from MFC's CPropertyPage class.



CAUSE
MMC's library function MMCPropPageCallback only maintains a single pointer to a property page callback function. The pointer is always set by the last call to this library function. When multiple property page callbacks are used at the same time in a single DLL, all the callbacks will point to the last set callback function, which might not be the one a particular page is expecting. An AV will likely happen if this last set callback function is expecting to interpret the page's data. For example, it might cast LPARAM to a pointer for a specific class. Use of this pointer will then likely cause an AV.



RESOLUTION
There are a several ways to work around this problem:
 * Call MMCPropPageCallback before you assign your custom callback to m_psp.pfnCallback. Then, MMC's internal pointer will always point to MFC's callback function AfxPropPageCallback.
 * Use a single callback function for multiple property pages.
 * Do not implement more than one snap-in in a single DLL.

Note When you are using CPropertyPage with MMC, it is required that you call MMCPropPageCallback to set the correct MFC module state during page creation.



STATUS
Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the &quot;Applies to&quot; section of this article.



How to use MMCPropPageCallback
One way to avoid the problem is to make sure that MMCPropPageCallback is called before you assign the custom callback in your derived class to m_psp.pfnCallback.

The following snippet of code is an example of how to do this: MMCPropSheetCallback( &m_psp ); m_pfnOldCallback = m_psp.pfnCallback; m_psp.pfnCallback = &MyCallbackFunction; This code can be in the property page object or it can be external. If it is in the property page class, it should be in the constructor. It should be executed before the property page object receives the WM_INITDIALOG message.

This should only be done for property pages that are derived from CPropertyPage. Property pages that are Win32-based would not normally need to implement this.

When you are implementing a callback, CPropertyPage::m_psp.dwFlags must include the PSP_USECALLBACK flag.

Keywords: kbbug kbnofix kbdswmanage2003swept KB309554

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.