Microsoft KB Archive/155436

= DOC: CImageList Returned from CreateDragImage Needs Delete =

Article ID: 155436

Article Last Modified on 11/21/2006

-

APPLIES TO

 Microsoft Foundation Class Library 4.2, when used with:  Microsoft Visual C++ 4.2 Professional Edition

 Microsoft Visual C++ 4.2 Enterprise Edition

 Microsoft Visual C++ 5.0 Learning Edition 

-

<div class="notice_section">

This article was previously published under Q155436

<div class="summary_section">

SUMMARY
The CTreeCtrl::CreateDragImage and CListCtrl::CreateDragImage functions in versions of MFC earlier than 4.2 return a pointer to a temporary CImageList object. In MFC version 4.2, CreateDragImage returns a permanent object that must be explicitly deleted.

The documentation for CreateDragImage does not state this.

This documentation error was fixed in Visual C++ version 5.0.

<div class="moreinformation_section">

MORE INFORMATION
In versions of MFC earlier than 4.2, MFC implements CreateDragImage as CImageList::FromHandle. An object returned from FromHandle is temporary and does not need to be explicitly deleted. A limitation of this implementation is that the CImageList pointer can be safely used only in the current message being processed.

CreateDragImage function was changed in Visual C++ version 4.2 to allocate a permanent CImageList object, and can now be used when handling multiple messages. When finished using the pointer returned by CreateDragImage, however, it is now necessary to explicitly delete the object: CImageList* pImageList = CreateDragImage( ...

delete pImageList; For more information on temporary handles returned from FromHandle, see MFC TechNote "TN003: Mapping of Windows Handles to Objects" in the Visual C++ Books Online.

Additional query words: kbVC420bug leak kbImgLst

Keywords: kbbug kbdocerr kbdocfix kbfix kbuidesign kbvc500fix KB155436

-

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

© Microsoft Corporation. All rights reserved.