PC Review


Reply
Thread Tools Rate Thread

DataObject.SetData to exact bytes, with no extra baloney?

 
 
Graham Wideman
Guest
Posts: n/a
 
      31st Aug 2003
Folks:

I am trying to use .NET's DataObject.SetData to set a particular format for
clipboards and drag and drop. But I am as yet unable to prevent .NET
DataObject from prefixing my desired data with some unwanted data.

(I can do the parallel operation just fine using my own implementation of
COM's IDataObject, but trying to do this the .NET way is the problem.)

The actual data content bytes I need to stick into DataObject happen to be a
string (8-bit, not Unicode if it matters). But the ClipboardFormat is not a
standard one like CF_TEXT.

So I use either:

ADataObject.SetData(cfMyFormatName, StringContainingData);

.... or...

ADataObject.SetData(cfMyFormatName, ByteArrayContainingData);

The result is that the data is indeed stuffed into ADataObject, but along
with some additional bytes before and one additional byte after the real
data.

I'm guessing that .NET DataObject is "helpfully" serializing the string or
byte array, rather than just sticking the contents into the DataObject.

How do I get .NET DataObject to just contain that actual bytes I give it,
and not add this extra stuff?

Thanks,

Graham

--
---------------------------------------------------
Graham Wideman
Microsoft Visio MVP
---------------------------------------------------
Book/Tools:
Visio 2002 Developer's Survival Pack
Resources for programmable diagramming at:
http://www.diagramantics.com
(E-Mail Removed)
..


 
Reply With Quote
 
 
 
 
Graham Wideman
Guest
Posts: n/a
 
      31st Aug 2003
.... and in case anyone else blunders down this path, the answer is...

First put the data in a byte array, which you then provide to a
MemoryStream, which you can *then* give to DataObject.SetObject. This
procedure results in a DataObject that offers the raw data bytes, rather
than what is apparently a searialized object wrapping of the bytes or
string.

OK, would have been nice to see that in the DataObject docs.

Graham

---------------------------------------------------
Graham Wideman
Microsoft Visio MVP
---------------------------------------------------
Book/Tools:
Visio 2002 Developer's Survival Pack
Resources for programmable diagramming at:
http://www.diagramantics.com
(E-Mail Removed)
..

"Graham Wideman" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> Folks:
>
> I am trying to use .NET's DataObject.SetData to set a particular format

for
> clipboards and drag and drop. But I am as yet unable to prevent .NET
> DataObject from prefixing my desired data with some unwanted data.
>
> (I can do the parallel operation just fine using my own implementation of
> COM's IDataObject, but trying to do this the .NET way is the problem.)
>
> The actual data content bytes I need to stick into DataObject happen to be

a
> string (8-bit, not Unicode if it matters). But the ClipboardFormat is not

a
> standard one like CF_TEXT.
>
> So I use either:
>
> ADataObject.SetData(cfMyFormatName, StringContainingData);
>
> ... or...
>
> ADataObject.SetData(cfMyFormatName, ByteArrayContainingData);
>
> The result is that the data is indeed stuffed into ADataObject, but along
> with some additional bytes before and one additional byte after the real
> data.
>
> I'm guessing that .NET DataObject is "helpfully" serializing the string or
> byte array, rather than just sticking the contents into the DataObject.
>
> How do I get .NET DataObject to just contain that actual bytes I give it,
> and not add this extra stuff?
>
> Thanks,
>
> Graham
>
> --
> ---------------------------------------------------
> Graham Wideman
> Microsoft Visio MVP
> ---------------------------------------------------
> Book/Tools:
> Visio 2002 Developer's Survival Pack
> Resources for programmable diagramming at:
> http://www.diagramantics.com
> (E-Mail Removed)
> .
>
>



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
StreamReader reads an extra 1,024 bytes... lord.zoltar@gmail.com Microsoft Dot NET 9 2nd Aug 2006 02:49 PM
copy exact values from RangeA to Range B which has extra rows =?Utf-8?B?Z3VwdGFzYUBnb3NzYW1pIC5jb20=?= Microsoft Excel Misc 1 16th May 2005 09:21 AM
BinaryWriter.Write() adding extra bytes? =?Utf-8?B?a3NtaXRo?= Microsoft Dot NET Framework 1 8th Mar 2005 10:14 PM
exact file size in bytes displayed in the Windows Explorer "Size"column? Larry__Weiss Windows XP Basics 3 4th Nov 2004 12:10 PM
copy XML file -- three extra bytes??? martin Microsoft ASP .NET 4 6th Mar 2004 12:58 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:53 AM.