The information in this article applies to:
SYMPTOMSWhen overriding CWnd::OnInitMenuPopup, while the CMenu pointer passed in is accessed, after calling the base class OnInitMenuPopup, the program may cause an ASSERT, access violation, or other problems. CAUSEIn MFC version 4.0 calls to AfxLockTempMaps and AfxUnlockTempMaps were added to CWnd::OnInitMenuPopup. When AfxUnlockTempMaps is called, MFC's temporary object map reference count will go to zero causing all temporary MFC objects to be deleted. When the call to OnInitMenuPopup returns, the CMenu pointer (which is a temporary) will be invalid. RESOLUTIONMake a call to AfxLockTempMaps before the call to the base class and a call to AfxUnlockTempMaps before returning from your OnInitMenuPopup override. This will stop the internal reference count from reaching zero inside CWnd::OnInitPopupMenu and the CMenu will not be deleted. STATUSMicrosoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. This bug was corrected in Visual C++ 4.1. MORE INFORMATION
MFC maintains a map from handles such as HMENUs to their C++ wrapper
objects. When a call is made to, for example, GetMenu, MFC attempts to find
the C++ wrapper object that corresponds to the HMENU ::GetMenu returns. If
no object in the permanent map is found, MFC creates a temporary object
that is normally destroyed in OnIdle processing by a call to
AfxUnlockTempMaps.
Sample Code to Reproduce or Resolve Problem
REFERENCES
MFC Technical Note 3: Mapping of Windows Handles to Objects.
Q139469 How to Use TrackPopupMenu() and Update UI Handlers Additional query words: kbVC400bug 4.00 4.10
Keywords : kbcode kbMFC KbUIDesign kbVC kbVC410fix |
Last Reviewed: September 2, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |