I’m trying to do the following trick:
- I have
IDataObject*to be set into the clipboard, so I’m usingOleSetClipboard()to set it into the clipboard. - I have another
CLIPFORMATI want to add to the clipboard, but I can’t do it withOleSetClipboard()because theIDataObject*I receive does not implementSetData()method. So, to overcome this limitation IOpenClipboard()withGetClipboardOwner(), this way, I canSetClipboardData()to the clipboard withoutEmptyClipboard()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 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.