IDataObject and COM Interop

"Hewitt, Simon C. (Contractor)" <[email protected]> Tue, 24 Mar 2009 09:20:19 -0000
Newsgroups gmane.comp.windows.devel.dotnet.advanced
Message-ID <A645D48BCCCDE241958AA3D84D34163BFBBE90@BP1XEUEX029-C.bp1.ad.bp.com>
I have a .NET IDataObject which contains some virtual file information. 

This all works fine and dandy in that I can use it in a drag-and-drop
process and let the user drop into a Windows Explorer folder.
I can also put it on the clipboard and let the user paste into a Windows
Explorer folder.
In both cases, I get a callback to stream the files and the OS takes
care of displaying the copy dialogue and copes with existing files etc.

What I would like to do is be able to 'force' a drop/paste (preferable a
drop since the clipboard can then be left as-is) directly into a named
folder.

I have managed to crib some code from a CodeProject article to use the
ShellFolder API to call GetUIObjectOf on the target folder and then get
a reference to IDropTarget and then call IDropTarget.DragDrop with a
pointer to a IDataObject (the COM interface one) and this seems to work
fine thus proving it can be done in theory. 

However in my test code, to get a COM IDataObject I was using
OleGetClipboard to get a 'real' COM IDataObject created by the article
app. I could not get it to work where the clipboard contents were set in
.NET code (AccessViolationException - Attempted to read or write
protected memory).

Is it possible to get a real COM IDataObject pointer from a .NET
IDataObject object and keep it pinned/ref-counted or whatever so that I
can pass it to an external API?

Cheers
Simon

===================================
View archives and manage your subscription(s) at http://peach.ease.lsoft.com/archives