views:

138

answers:

1

If using COleDataSource & COleDataObject, you allocate some global memory for each clipboard data format you wish to store data in the drag'n'drop operation. In the drop code, you query if the object has data in the format(s) you want and can then access & free that memory.

But as a drop-target you can't know all the formats that might have data associated by the drag-source. So how can you clear all the memory allocated for the drag for every format?

In fact, am I supposed to manually free this data on the drop, or let MFC/Ole do it automatically?

+1  A: 

Once you pass the handle to the COleDataSource, it owns the memory, not you. You don't need to free the global memory.

You are supposed to enumerate available data formats in the COleDataObject object using BeginEnumFormats and GetNextFormat until you find one that you are interested in. For example, if you understands CF_HTML, you don't need to handle CF_UNICODETEXT or CF_TEXT unless the user instructed you to discard the HTML formating and only make a text-only drop/paste.

Sheng Jiang 蒋晟