Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Clipboard and IStorage

Clipboard and IStorage

Scheduled Pinned Locked Moved C#
tutorialquestion
4 Posts 2 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • O Offline
    O Offline
    Oleksandr Kucherenko
    wrote on last edited by
    #1

    Hi! Anybody know how to put IStorage or IStream interface into NET clipboard? (with example please) Good Luck Alex Kucherenko

    H 1 Reply Last reply
    0
    • O Oleksandr Kucherenko

      Hi! Anybody know how to put IStorage or IStream interface into NET clipboard? (with example please) Good Luck Alex Kucherenko

      H Offline
      H Offline
      Heath Stewart
      wrote on last edited by
      #2

      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 for IStorage does not. You'll have to create an interface with the proper GuidAttribute and interface methods (taking into account marshaling parameters). To do this correctly, you'll have to implement .NET's IDataObject yourself and recreate structures for FORMATETC and STGMEDIUM. .NET's IDataObject 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's IDataObject interface. After that, simply call Clipboard.SetDataObject(object) or Clipboard.SetDataObject(object,bool) in your client code. My recommendations, make your IDataObject 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 an IStorage or IStream 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 at FORMATETC and STDMEDIUM. 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-----

      O 1 Reply Last reply
      0
      • H Heath Stewart

        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 for IStorage does not. You'll have to create an interface with the proper GuidAttribute and interface methods (taking into account marshaling parameters). To do this correctly, you'll have to implement .NET's IDataObject yourself and recreate structures for FORMATETC and STGMEDIUM. .NET's IDataObject 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's IDataObject interface. After that, simply call Clipboard.SetDataObject(object) or Clipboard.SetDataObject(object,bool) in your client code. My recommendations, make your IDataObject 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 an IStorage or IStream 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 at FORMATETC and STDMEDIUM. 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-----

        O Offline
        O Offline
        Oleksandr Kucherenko
        wrote on last edited by
        #3

        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

        H 1 Reply Last reply
        0
        • O Oleksandr 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

          H Offline
          H Offline
          Heath Stewart
          wrote on last edited by
          #4

          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 the System.Windows.Forms.DataObject does. You can use reflection to set the FORMATETC and STGMEDIUM structs. Calling Clipboard.SetDataObject does, in fact, call OleSetClipboard. You should try downloading .NET Reflector and take a look at how Clipboard.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 your IOleDataObject won't be the same Type as theirs, but you can at least make your call to OleSetClipboard work the same). With that, I can understand how your interface methods aren't always correct. This happens often. I had a custom IClassFactory 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 your IOleDataObject interface defined correctly (remember, don't forget the GuidAttribute), you can pass the object directly into a correctly imported call to OleSetClipboard.

          -----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-----

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups