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