Search code examples
c++multithreadingmfccomole

MFC: Windows Explorer-like application to export files in parallel with its main thread


a question for true experts: How is it made that a Paste operation on OLE target causes the OLE source to begin supplying data?

I'm creating a MFC-based Windows Explorer-like app to copy/cut/paste virtual files from/to somewhere (using drag&drop, and OLE clipboard). The problem I struggle now with is how to make the export of files parallel with the main window thread. As said it's an MFC app so I export the virtual file content in the COleDataSource::OnRenderFileData function. This function is nowhere in the application called explicitly, yet is it called by the main window thread. I digged into it, and found that MFC handles a certain command (CN_COMMAND) that is processed by the document's OnCmdMsg function - that explains how the main thread invokes OnRenderFileData.

But as I'm working on VS2010 Express edition with legacy (but free) MFC4.2, I can't track down the point where some magical message is received (from COM?) and processed by the MFC main thread. I'd like to override such point to make the virtual files export in parallel with the application's main thread.

Thanks a lot for any suggestions

Tomas


Solution

  • The "magical" message you are talking about is WM_RENDERFORMAT, which is sent to the owner of Clipboard who requested delayed rendering.

    I believe that you are expected to call SetClipboardData() BEFORE returning from that message handler, so I don't see how another thread may work; the caller will try to access the data on the Clipboard as soon as his SendMessage(..., WM_RENDERFORMAT, ...) returns.

    P.S. Is there a reason you are using Express edition? The new versions of Visual Studio (2013 and 2015) are available in Community Edition, which is free for experimental and educational use, and them some. It includes a modern version of MFC, too.