Article View: borland.public.cppbuilder.nativeapi
Article #618Re: Getting binary data from the clipboard
From: Asger Joergensen
Date: Sat, 09 Feb 2008 10:37
Date: Sat, 09 Feb 2008 10:37
71 lines
2999 bytes
2999 bytes
Hi Paul
Paul says:
> OK I need to be specific :)
>
> I am using a third party application (that has an inbuilt hex viewer) that I
> use to copy data onto the clipboard - I have no idea what format the data is
> in. I want to paste the data into a hex editor that I have written.
>
> I have a third party hex editor which I can paste the same copied data
> into - so the clipboard data is clearly in a format that can be used - I
> just need to know how to get at it.
Have You tried pasting the data into notepad or the BCB editor
it might be in a text format.
if so this should work:
char Buf[200];
TClipboard().GetTextBuf(Buf, 200);
If not You have to get the clipboard format and see what
formats that are available, in my xvi32 Hex editor the format
has number 49883
So I made this little test app:
A new project with a listbox and two buttons and it seem to work,
but there is 4 extra bytes at the beginning of the memory and I
also need to say that I don't know if this is the right way to do it.
Kind regards
Asger
void __fastcall TForm1::Button1Click(TObject *Sender)
{
ListBox1->Clear();
for(int i = 0; i < Clipboard()->FormatCount; i++)
ListBox1->Items->Add(IntToStr(Clipboard()->Formats[i]));
}
//-----------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
HGLOBAL Hnd = (void*)TClipboard().GetAsHandle(49883);
if( ! Hnd)
return;
String Hex;
int Size = ::GlobalSize(Hnd);
if(Size)
{
Byte* Mem;
try{
::GlobalLock(Hnd);
Mem = new Byte[Size];
::CopyMemory(Mem, Hnd, Size);
for(int i = 0; i < Size; ++i)
Hex += IntToHex(Mem[i], 2) + " ";
}__finally{
::GlobalUnlock(Hnd);
delete[] Mem;
}
}
Caption = Hex;
}
//---------------------------------------------------------
Technical Details
Message-ID:
<MPG.2217a0eb16f624a2989a58@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!feeder1-2.proxad.net!proxad.net!feeder1-1.proxad.net!ecngs!feeder2.ecngs.de!newsfeed.freenet.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<47aceda1$1@newsgroups.borland.com> <MPG.221719ed59086717989a55@newsgroups.borland.com> <47ad5ffd@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,c5ac8670671c8a0e X-Google-Attributes: gid10cc67,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit From: Asger Joergensen <junk@Asger-P.dk> Newsgroups: borland.public.cppbuilder.nativeapi Subject: Re: Getting binary data from the clipboard Date: Sat, 9 Feb 2008 11:37:52 +0100 Message-ID: <MPG.2217a0eb16f624a2989a58@newsgroups.borland.com> References: <47aceda1$1@newsgroups.borland.com> <MPG.221719ed59086717989a55@newsgroups.borland.com> <47ad5ffd@newsgroups.borland.com> Organization: Asger-P MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit User-Agent: MicroPlanet-Gravity/2.70.2067 NNTP-Posting-Host: 83.73.220.89 X-Trace: newsgroups.borland.com 1202553469 83.73.220.89 (9 Feb 2008 02:37:49 -0700) Lines: 72 Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!feeder1-2.proxad.net!proxad.net!feeder1-1.proxad.net!ecngs!feeder2.ecngs.de!newsfeed.freenet.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail