FIX: OnInitMenuPopup Deletes Temporary Objects (141532)
The information in this article applies to:
- The Microsoft Foundation Classes (MFC), when used with:
- Microsoft Visual C++, 32-bit Editions 4.0
This article was previously published under Q141532 SYMPTOMS
When 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.
CAUSE
In 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.
RESOLUTION
Make 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.
STATUS
Microsoft 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.
REFERENCES
MFC Technical Note 3: Mapping of Windows Handles to Objects.
For more information, please see the following article in the Microsoft
Knowledge Base:
139469 How to Use TrackPopupMenu() and Update UI Handlers
Modification Type: | Major | Last Reviewed: | 10/24/2003 |
---|
Keywords: | kbBug kbfix kbNoUpdate KbUIDesign kbVC410fix KB141532 |
---|
|