DOC: CDC::SelectObject, CDC::SelectStockObject Return (117686)
The information in this article applies to:
- The Microsoft Foundation Classes (MFC), when used with:
- Microsoft C/C++ for MS-DOS 7.0
- Microsoft Visual C++ for Windows, 16-bit edition 1.0
- Microsoft Visual C++ for Windows, 16-bit edition 1.5
- Microsoft Visual C++ for Windows, 16-bit edition 1.51
- Microsoft Visual C++ for Windows, 16-bit edition 1.52
- Microsoft Visual C++, 32-bit Editions 1.0
- Microsoft Visual C++, 32-bit Editions 2.0
This article was previously published under Q117686 SUMMARY
The pointer to a CGdiObject that is returned from CDC::SelectObject() or CDC::SelectStockObject() is stored for use. When the pointer is used later, it causes unexpected behavior [for example, a general protection fault (GPF) or heap corruption].
The documentation for the SelectObject() member does not make clear that the pointer returned from the call might point to a temporary object that is only valid during processing of one Windows message. This is an error in the documentation.
The CDC::SelectObject() and CDC::SelectStockObject() functions make a call to CGdiObject::FromHandle() to determine which CGdiObject object to return. If there is no CGdiObject object attached to the Windows GDI object that is currently selected in the DC, then a temporary object is created. See the documentation for CGdiObject::FromHandle() for further information.
REFERENCES
For further information on mapping C++ objects to handles in the MFC, see
MFC TechNote #3, "Mapping of Windows Handles to Objects."
NOTE: The documentation for Visual C++ 2.0 (MFC 3.0) has been corrected.
Modification Type: | Major | Last Reviewed: | 12/2/2003 |
---|
Keywords: | kbBug kbdocfix kbVC200fix KB117686 |
---|
|