Clipboard and IStorage
-
Hi! Anybody know how to put IStorage or IStream interface into NET clipboard? (with example please) Good Luck Alex Kucherenko
-
Hi! Anybody know how to put IStorage or IStream interface into NET clipboard? (with example please) Good Luck Alex Kucherenko
This really requires quite a bit of knowledge of OLE/COM. Remember that the .NET clipboard (and drag and drop functions) are just wrappers for their Win32 counterparts. The same stuff is possible, but in many cases you have to recreate some structs, enums, and interface definitions for stuff that is already in Win32. For example, the
System.Runtime.InteropServices.UCOMISTream
interface already exists, but an equivalent forIStorage
does not. You'll have to create an interface with the properGuidAttribute
and interface methods (taking into account marshaling parameters). To do this correctly, you'll have to implement .NET'sIDataObject
yourself and recreate structures forFORMATETC
andSTGMEDIUM
. .NET'sIDataObject
is created specifically for .NET, using objects instead of structs and interface pointers. You'll have to override it to make it work more like COM'sIDataObject
interface. After that, simply callClipboard.SetDataObject(object)
orClipboard.SetDataObject(object,bool)
in your client code. My recommendations, make yourIDataObject
implementation class take an object (perhaps of a specific type) and some other parameter to dictate whether the implementaiton itself should wrap it up in anIStorage
orIStream
object. So, I'm sorry there isn't example code like you asked, but this is actually a very big problem to solve and requires that you read-up on COM to understand it. Be sure to look atFORMATETC
andSTDMEDIUM
. Both contains links to other material that should be helpful.-----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----
-
This really requires quite a bit of knowledge of OLE/COM. Remember that the .NET clipboard (and drag and drop functions) are just wrappers for their Win32 counterparts. The same stuff is possible, but in many cases you have to recreate some structs, enums, and interface definitions for stuff that is already in Win32. For example, the
System.Runtime.InteropServices.UCOMISTream
interface already exists, but an equivalent forIStorage
does not. You'll have to create an interface with the properGuidAttribute
and interface methods (taking into account marshaling parameters). To do this correctly, you'll have to implement .NET'sIDataObject
yourself and recreate structures forFORMATETC
andSTGMEDIUM
. .NET'sIDataObject
is created specifically for .NET, using objects instead of structs and interface pointers. You'll have to override it to make it work more like COM'sIDataObject
interface. After that, simply callClipboard.SetDataObject(object)
orClipboard.SetDataObject(object,bool)
in your client code. My recommendations, make yourIDataObject
implementation class take an object (perhaps of a specific type) and some other parameter to dictate whether the implementaiton itself should wrap it up in anIStorage
orIStream
object. So, I'm sorry there isn't example code like you asked, but this is actually a very big problem to solve and requires that you read-up on COM to understand it. Be sure to look atFORMATETC
andSTDMEDIUM
. Both contains links to other material that should be helpful.-----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----
Hi! this is not realy what i want... I mae port of structures and interfaces long time ago, but I think I make something wrong... that is why I ask for example of code. BTW Heath Stewart wrote: After that, simply call Clipboard.SetDataObject(object) or Clipboard.SetDataObject(object,bool) in your client code. such code will not work with Clipboard implementation provided by NET Framework. That is why I need example with OleSetClipboard and OleGetClipboard API methods calls. Good Luck Alex Kucherenko
-
Hi! this is not realy what i want... I mae port of structures and interfaces long time ago, but I think I make something wrong... that is why I ask for example of code. BTW Heath Stewart wrote: After that, simply call Clipboard.SetDataObject(object) or Clipboard.SetDataObject(object,bool) in your client code. such code will not work with Clipboard implementation provided by NET Framework. That is why I need example with OleSetClipboard and OleGetClipboard API methods calls. Good Luck Alex Kucherenko
Actually, such a call will work if you take something into account that I forgot to mention (sorry). If the data object implements
System.Windows.Forms.UnsafeNativeMethods.IOleDataObject
, it does work. Unfortunatel, it is a nested interface of an internal class, but theSystem.Windows.Forms.DataObject
does. You can use reflection to set theFORMATETC
andSTGMEDIUM
structs. CallingClipboard.SetDataObject
does, in fact, callOleSetClipboard
. You should try downloading .NET Reflector and take a look at howClipboard.SetDataObject
is done. Like I said, everything you need is already there. You may have to use Reflection to do get at it or you could redefine your own structs and interfaces in the same way it does (except that yourIOleDataObject
won't be the same Type as theirs, but you can at least make your call toOleSetClipboard
work the same). With that, I can understand how your interface methods aren't always correct. This happens often. I had a customIClassFactory
method with the same params. When I tried a trick where you write IDL, compile it with midl.exe to a typelib, then use tlbimp.exe to import that, the method had a mysterious third parameter. Using Reflector (that can disassemble in a much easier-to-follow way than ildasm.exe, and can also decompile), you can see how MS defined their interfaces and match them. Once you get yourIOleDataObject
interface defined correctly (remember, don't forget theGuidAttribute
), you can pass the object directly into a correctly imported call toOleSetClipboard
.-----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----