I am implementing copy/paste functionality within my editor and I have encountered a problem when implementing the feature on windows. I'm using the OLE API, and creating a custom IDataObject subclass to provide the data to the clipboard. For now I have been testing with just text data.
My IDataObject and IEnumFORMATETC subclasses look like this:
To copy some text onto the clipboard I use this:
// global
DataObject data;
void copy()
{
OleSetClipboard( &data );
}
This should copy the static text "Hello dude!" into the clipboard. I can then paste that text within my application without any issues by calling GetClipboardData(CF_UNICODETEXT). However, if I try to paste the copied text into another application (e.g. visual studio or wordpad), it causes that external application to freeze until my application quits. If I follow OleSetClipboard() by a call to OleFlushClipboard(), the string is rendered to the clipboard (GetData is called), and everything works as expected. However, I can't take this approach in general because it's wasteful if I render large objects (e.g. images, sounds) to the clipboard every single time, rather than deferring rendering those objects until another application requests a particular format.
This seems to imply that some mutex/lock is not being properly released, but I can't seem to figure out where.
Any leads?
↧