Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to copy binary data to the clipboard ?

962 views
Skip to first unread message

Dominic Curran

unread,
Jan 26, 2001, 9:10:14 PM1/26/01
to

I'm writting a hex editor.
I would like to know the best way to copy binary data to the clipboard
?
(i.e. data that might include printable and well as non-printable ASCII
characters)

I have been using
::SetClipboardData(CF_TEXT, hMem);

where hMem is a handle that has come back from
GlobalAlloc(GMEM_MOVEABLE, dwBytes)

However i have found that using the CF_TEXT causes the clipboard to
insert a 0x00 at the end of my array of binary data.

I could create my own clipboard format, but that would mean that I would
not be able to paste data into other apps (like NotePad) when the data
was actually printable text.

Is there a CF_BINARY format that I have missed ?

Anyone have a good solution for this ?

Thanks in advance
dom

--

dcu...@ANTISPAMti.com
Please remove ANTISPAM from line above to reply to correct address.

gott...@my-deja.com

unread,
Jan 26, 2001, 11:53:16 PM1/26/01
to
One way is to send your data to the clipboard as normal and also send
one to your own buffer. When a person pushes paste in your program it
extracts from your buffer only.

Or..
when you push paste in your program ...use the clipboard stored info
and then kill the last character. Hence getting rid of 0x00

Later,
Steve


Sent via Deja.com
http://www.deja.com/

James Brown

unread,
Jan 27, 2001, 7:38:36 AM1/27/01
to
The best way to handle this is to send the data as
CF_TEXT format. As well as this,
paste another clipboard object (a private one
that you register) at the same time, which is just 4 bytes in size.
This clipboard object is an integer, an will tell your program how
many bytes the CF_TEXT object really contains. Programs
like notepad will not know about this extra clipboard object
and wont get all of the CF_TEXT object if a 0x00 is somewhere in
the middle, but your program will be able to exactly deduce how
many bytes is stored. If the extra clipboard object isn't present,
(i.e. it wasn't your program that put the CF_TEXT on the clipboard)
then just deduce the length of the text object using lstrlen(..)

This is how alot of hexeditors work (I know because I'm writing
one at the minute).

James

"Dominic Curran" <dcu...@ANTISPAMti.com> wrote in message
news:3A722E06...@ANTISPAMti.com...

Dominic Curran

unread,
Jan 27, 2001, 7:07:53 PM1/27/01
to James Brown

Thanks, that helps alot.

I was thinking of using GlobalHandle and then GlobalSize, but I think
thats going to return the number of bytes GlobalAlloc real allocated on
the copy, rather than the number I asked for, which might mean I pasted
more bytes than I copied.

Your ways much better.

thanks again
dom

0 new messages