Article View: borland.public.cppbuilder.nativeapi
Article #634Re: Getting binary data from the clipboard
From: Remy Lebeau (TeamB)
Date: Mon, 11 Feb 2008 18:49
Date: Mon, 11 Feb 2008 18:49
99 lines
4216 bytes
4216 bytes
"Asger Joergensen" <junk@Asger-P.dk> wrote in message
news:MPG.2217a0eb16f624a2989a58@newsgroups.borland.com...
> if so this should work:
>
> char Buf[200];
> TClipboard().GetTextBuf(Buf, 200);
TClipboard is a VCL-based class. It cannot be instantiated on the stack
like that. You need to use the global Clipboard() function instead, ie:
char Buf[200];
if( Clipboard()->GetTextBuf(Buf, 200) > 0 )
{
// use Buf ...
}
Or:
AnsiString Buf = Clipboard()->AsText;
if( !Buf.IsEmpty() )
// use Buf ...
> in my xvi32 Hex editor the format has number 49883
That is a custom format that was registerd using RegisterClipboardFormat()
at runtime. As such, it is not not a static value. Reboot the machine and
you will see the clipboard format use a different value next time. To work
with such values, you must call RegisterClipboardFormat() in your own code
to retreive the current value that the original app is also using to fill
the clipboard with. To know the name of that value when it was registered,
you can use GetClipboardFormatName() to get the format name and then put
that into your code when calling RegisterClipboardFormat().
> there is 4 extra bytes at the beginning of the memory
Chances are, that is the actual byte count (or character count) of the data.
GlobalSize() returns the byte size of the HGLOBAL that was allocated for the
data, and thus may be larger than the data size due to memory alignment and
such. GlobalSize() does not report the size of the actual data itself. For
example:
private:
UINT uiDataFormat;
__fastcall TForm1::TForm1(TComponent *Owner)
{
uiDataFormat = ::RegisterClipboardFormat("TheFormatNameHere");
}
void __fastcall TForm1::Button2Click(TObject *Sender)
{
if( uiDataFormat == 0 )
return;
Clipboard()->Open();
try
{
if( Clipboard()->HasFormat(uiDataFormat) )
{
HGLOBAL hGlobal = (HGLOBAL)
Clipboard()->GetAsHandle(uiDataFormat);
if( hGlobal )
{
LPVOID pData = ::GlobalLock(hGlobal);
if( pData )
{
try
{
DWORD dwSize = * (LPDWORD) pData;
String Hex;
for(DWORD i = 0; i < dwSize; ++i)
Hex += IntToHex(pData[i], 2) + " ";
Memo1->Text = Hex;
}
__finally
{
::GlobalUnlock(hGlobal);
}
}
}
}
}
__finally
{
Clipboard()->Close();
}
}
> I also need to say that I don't know if this is the right way
> to do it.
Why not just contact the author of the original app and ask?
Gambit
Technical Details
Message-ID:
<47b098b3$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.germany.com!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> <MPG.2217a0eb16f624a2989a58@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: "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <47aceda1$1@newsgroups.borland.com> <MPG.221719ed59086717989a55@newsgroups.borland.com> <47ad5ffd@newsgroups.borland.com> <MPG.2217a0eb16f624a2989a58@newsgroups.borland.com> Subject: Re: Getting binary data from the clipboard Date: Mon, 11 Feb 2008 10:49:58 -0800 Lines: 101 Organization: Lebeau Software X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.3138 X-RFC2646: Format=Flowed; Original X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3198 NNTP-Posting-Host: 207.178.157.90 Message-ID: <47b098b3$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1202755763 207.178.157.90 (11 Feb 2008 10:49:23 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.germany.com!newsfeed.freenet.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail