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. Passing an unmanaged buffer to DataObject

Passing an unmanaged buffer to DataObject

Scheduled Pinned Locked Moved C#
helpcsharpc++businesssales
8 Posts 2 Posters 0 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.
  • C Offline
    C Offline
    Code o mat
    wrote on last edited by
    #1

    Hello people! I am getting a buffer (allocated with CoTaskMemAlloc) from an unmanaged DLL call along with the buffer's size. I would like to feed this buffer (or a copy of this buffer) to DataObject (and drag-drop it...). Is it possible and if yes, how? I've been coding in C++ for many years now (so i am not new to the concept of the whole programming business), but i'm relatively new to C#, so please keep it simple for me. Thanks in advance for any answers.

    > The problem with computers is that they do what you tell them to do and not what you want them to do. < > "It doesn't work, fix it" does not qualify as a bug report. < > Amazing what new features none of the programmers working on the project ever heard of you can learn about when reading what the marketing guys wrote about it. <

    L 1 Reply Last reply
    0
    • C Code o mat

      Hello people! I am getting a buffer (allocated with CoTaskMemAlloc) from an unmanaged DLL call along with the buffer's size. I would like to feed this buffer (or a copy of this buffer) to DataObject (and drag-drop it...). Is it possible and if yes, how? I've been coding in C++ for many years now (so i am not new to the concept of the whole programming business), but i'm relatively new to C#, so please keep it simple for me. Thanks in advance for any answers.

      > The problem with computers is that they do what you tell them to do and not what you want them to do. < > "It doesn't work, fix it" does not qualify as a bug report. < > Amazing what new features none of the programmers working on the project ever heard of you can learn about when reading what the marketing guys wrote about it. <

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      The details depend on the kind of information you want to represent (string, image, simple binary, ...). Think of it as a two-step prrocess: first make a managed object that actually holds your data (string, image, etc); then use this[^] DataObject constructor. :)

      Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

      Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

      C 1 Reply Last reply
      0
      • L Luc Pattyn

        The details depend on the kind of information you want to represent (string, image, simple binary, ...). Think of it as a two-step prrocess: first make a managed object that actually holds your data (string, image, etc); then use this[^] DataObject constructor. :)

        Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

        Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

        C Offline
        C Offline
        Code o mat
        wrote on last edited by
        #3

        Thanks for the answer. The data is actually a shell item ID list, i supose i should add this as "pure" binary data, it can't be converted into a string (as far as i know), so basicly i guess my quesiton is: what do i "wrap" this into? This might be a basic question but as said, i don't yet have a well enough oversight with C#. I was looking at the *Ptr* methods in the Marshal class but i don't see which i could use, i tried reading the binary data byte-by-byte (Using Marshal.ReadByte) and add them to a list<byte> (yeah, it's a stupid idea but hell, i had to try), i could add this then to the data object with DataObject.SetData, but of course in the end i didn't get what i was looking for. Now i wonder if i could use one of the Copy methods to copy data from the unmanaged buffer to a managed byte[] array and then add that to the DataObject...

        > The problem with computers is that they do what you tell them to do and not what you want them to do. < > "It doesn't work, fix it" does not qualify as a bug report. < > Amazing what new features none of the programmers working on the project ever heard of you can learn about when reading what the marketing guys wrote about it. <

        L 1 Reply Last reply
        0
        • C Code o mat

          Thanks for the answer. The data is actually a shell item ID list, i supose i should add this as "pure" binary data, it can't be converted into a string (as far as i know), so basicly i guess my quesiton is: what do i "wrap" this into? This might be a basic question but as said, i don't yet have a well enough oversight with C#. I was looking at the *Ptr* methods in the Marshal class but i don't see which i could use, i tried reading the binary data byte-by-byte (Using Marshal.ReadByte) and add them to a list<byte> (yeah, it's a stupid idea but hell, i had to try), i could add this then to the data object with DataObject.SetData, but of course in the end i didn't get what i was looking for. Now i wonder if i could use one of the Copy methods to copy data from the unmanaged buffer to a managed byte[] array and then add that to the DataObject...

          > The problem with computers is that they do what you tell them to do and not what you want them to do. < > "It doesn't work, fix it" does not qualify as a bug report. < > Amazing what new features none of the programmers working on the project ever heard of you can learn about when reading what the marketing guys wrote about it. <

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          What you're after is probably burried in here[^], it may be steep but I expect it is the best article on the subject and it has a code download. :)

          Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

          Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

          C 1 Reply Last reply
          0
          • L Luc Pattyn

            What you're after is probably burried in here[^], it may be steep but I expect it is the best article on the subject and it has a code download. :)

            Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

            Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

            C Offline
            C Offline
            Code o mat
            wrote on last edited by
            #5

            Thanks, i'll try to dig into it, but it looks "scary" at first. :)

            > The problem with computers is that they do what you tell them to do and not what you want them to do. < > "It doesn't work, fix it" does not qualify as a bug report. < > Amazing what new features none of the programmers working on the project ever heard of you can learn about when reading what the marketing guys wrote about it. <

            L 1 Reply Last reply
            0
            • C Code o mat

              Thanks, i'll try to dig into it, but it looks "scary" at first. :)

              > The problem with computers is that they do what you tell them to do and not what you want them to do. < > "It doesn't work, fix it" does not qualify as a bug report. < > Amazing what new features none of the programmers working on the project ever heard of you can learn about when reading what the marketing guys wrote about it. <

              L Offline
              L Offline
              Luc Pattyn
              wrote on last edited by
              #6

              If you feel new and uncomfortable about .NET and C#, maybe you should attempt something easier and less scary first? :)

              Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

              Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

              C 1 Reply Last reply
              0
              • L Luc Pattyn

                If you feel new and uncomfortable about .NET and C#, maybe you should attempt something easier and less scary first? :)

                Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

                Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

                C Offline
                C Offline
                Code o mat
                wrote on last edited by
                #7

                I already did a few basic things to get aquainted with C#, it looks more friendly and welcoming as i originally expected it to be. I'm now experimenting with mixing managed and unmanaged code and drag and drop. What i did was to create a temporary jpeg image and try to drag-drop it. However, most of the time, the drag-drop of the image to applications results in no visible effect. I used ClipSpy to compare a dragdrop from the app and a dragdrop from the shell (expolorer), my guess is that most programs use the "Item IDList Array" in the data to open the dragged file, however, the dragged data from C# does not contain this. I googled around but didn't find anything satisfying, or i just googled for the wrong terms, so i wrote unmanaged code that generates the IDList array from a path into an array allocated with CoTaskMemAlloc and then i hit the problem of not knowing what to do with this buffer once i got it in C#. I might be trying to re-invent the wheel here but at least i am learning. :) Am not yet sure if the article about writing a shell extension and avoiding the ItemIDList can help me or not.

                > The problem with computers is that they do what you tell them to do and not what you want them to do. < > "It doesn't work, fix it" does not qualify as a bug report. < > Amazing what new features none of the programmers working on the project ever heard of you can learn about when reading what the marketing guys wrote about it. <

                L 1 Reply Last reply
                0
                • C Code o mat

                  I already did a few basic things to get aquainted with C#, it looks more friendly and welcoming as i originally expected it to be. I'm now experimenting with mixing managed and unmanaged code and drag and drop. What i did was to create a temporary jpeg image and try to drag-drop it. However, most of the time, the drag-drop of the image to applications results in no visible effect. I used ClipSpy to compare a dragdrop from the app and a dragdrop from the shell (expolorer), my guess is that most programs use the "Item IDList Array" in the data to open the dragged file, however, the dragged data from C# does not contain this. I googled around but didn't find anything satisfying, or i just googled for the wrong terms, so i wrote unmanaged code that generates the IDList array from a path into an array allocated with CoTaskMemAlloc and then i hit the problem of not knowing what to do with this buffer once i got it in C#. I might be trying to re-invent the wheel here but at least i am learning. :) Am not yet sure if the article about writing a shell extension and avoiding the ItemIDList can help me or not.

                  > The problem with computers is that they do what you tell them to do and not what you want them to do. < > "It doesn't work, fix it" does not qualify as a bug report. < > Amazing what new features none of the programmers working on the project ever heard of you can learn about when reading what the marketing guys wrote about it. <

                  L Offline
                  L Offline
                  Luc Pattyn
                  wrote on last edited by
                  #8

                  When you need P/Invoke (managed code calling native code), this article of mine[^] might be useful. :)

                  Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

                  Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

                  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