简体   繁体   中英

Unexpected/weird results using OLE clipboard and classic clipboard, or do I miss something?

I'm trying to do the following trick:

  1. I have IDataObject* to be set into the clipboard, so I'm using OleSetClipboard() to set it into the clipboard.
  2. I have another CLIPFORMAT I want to add to the clipboard, but I can't do it with OleSetClipboard() because the IDataObject* I receive does not implement SetData() method. So, to overcome this limitation I OpenClipboard() with GetClipboardOwner() , this way, I can SetClipboardData() to the clipboard without EmptyClipboard() first.

Now, it all works well, but what happens is that OleGetClipboard() does not return the data I placed in the clipboard using SetClipboardData() , but I can using GetClipboardData() .

I can imagine why this happens (It just returns the IDataObject* ), so I tried to OleFlushClipboard() to delete the IDataObject* , and OleGetClipboard() again to let the OS rebuild a new IDataObject* , and it still didn't contain the CLIPFORMAT added by SetClipboardData() .

Does anyone have any idea how to overcome this issue? or a different trick? or even explain why it works this way? Thanks

I just tried this (on Windows 7) and it appears to work but only cross-process:

  • In a different process to the clipboard owner, OleGetClipboard returns a data object that contains all of the formats (ie the original formats from the data object and the extra ones added to the clipboard).
  • In the same process, OleGetClipboard always returns a data object that does not contain the extra clipboard formats.

In both cases, calling OleFlushClipboard makes no difference.

Anyway, this doesn't seem like a terribly robust solution. What you can do instead is create your own data object that responds to the formats it knows about and delegates other formats to the original data object. The EnumFormatEtc method would combine formats from both objects, and so on. This article has the skeleton of a simple data object you could extend.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM