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

G

Graham Wideman

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 address removed)
..
 
G

Graham Wideman

.... 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 address removed)
..
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top