Thread View: borland.public.cppbuilder.nativeapi
12 messages
12 total messages
Started by Paul
Sat, 09 Feb 2008 00:02
Getting binary data from the clipboard
Author: Paul
Date: Sat, 09 Feb 2008 00:02
Date: Sat, 09 Feb 2008 00:02
4 lines
1085 bytes
1085 bytes
Hi Iam using a hex editor and copying some data to the clipboard - I want to paste it into another application - how do I go about this?
Re: Getting binary data from the clipboard
Author: Remy Lebeau (TeamB)
Date: Sat, 09 Feb 2008 00:57
Date: Sat, 09 Feb 2008 00:57
16 lines
1500 bytes
1500 bytes
"Paul" <someone@microsoft.com> wrote in message news:47aceda1$1@newsgroups.borland.com... > I am using a hex editor and copying some data to the clipboard What kind of data? Does the hex editor store multiple representations of the data, such as the hex out and binary together as different clipboard formats? > I want to paste it into another application - how do I go about this? Did you write the hex editor yourself? Or are you using something else's? Gambit
Re: Getting binary data from the clipboard
Author: Asger Joergensen
Date: Sat, 09 Feb 2008 01:01
Date: Sat, 09 Feb 2008 01:01
13 lines
1202 bytes
1202 bytes
Hi Paul Paul says: > Hi > > Iam using a hex editor and copying some data to the clipboard - I want to > paste it into another application - how do I go about this? What format are You copying to the clipboard ? Kind regards Asger
Re: Getting binary data from the clipboard
Author: Paul
Date: Sat, 09 Feb 2008 08:10
Date: Sat, 09 Feb 2008 08:10
9 lines
1457 bytes
1457 bytes
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.
Re: Getting binary data from the clipboard
Author: 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;
}
//---------------------------------------------------------
Re: Getting binary data from the clipboard
Author: Asger Joergensen
Date: Sat, 09 Feb 2008 10:49
Date: Sat, 09 Feb 2008 10:49
19 lines
1420 bytes
1420 bytes
Hi Asger Asger Joergensen says: > > 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 it is text this is easier: String Txt = TClipboard().AsText; Kind regards Asger
Re: Getting binary data from the clipboard
Author: Remy Lebeau (TeamB)
Date: Mon, 11 Feb 2008 18:30
Date: Mon, 11 Feb 2008 18:30
30 lines
1998 bytes
1998 bytes
"Paul" <someone@microsoft.com> wrote in message news:47ad5ffd@newsgroups.borland.com... > I am using a third party application (that has an inbuilt hex viewer) > that I use to copy data onto the clipboard Then you are limited to whatever formats that app decides to put on the clipboard. > I have no idea what format the data is in. You can use the Win32 API EnumClipboardFormats() and GetClipboardFormatName() functions (or find a third-party clipboard viewer app) for that. > I want to paste the data into a hex editor that I have written. Then you first need to find out what format(s) are actually on the clipboard to begin with. Copy some data from the app, see how the clipboard was modified, and then report back here with the results. > I have a third party hex editor which I can paste the same copied > data into Then the original app is using a clipboard format that the second app recognizes. Gambit
Re: Getting binary data from the clipboard
Author: 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
Re: Getting binary data from the clipboard
Author: Asger Joergensen
Date: Tue, 12 Feb 2008 00:01
Date: Tue, 12 Feb 2008 00:01
22 lines
1715 bytes
1715 bytes
Hi Remy Remy Lebeau (TeamB) says: > > "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: No doubt that You are right as usual, but 'cannot' might be a little strong in this case, since the code I posted compiles and run just fine in my BCB5. Kind regards Asger
Re: Getting binary data from the clipboard
Author: Remy Lebeau (TeamB)
Date: Tue, 12 Feb 2008 00:25
Date: Tue, 12 Feb 2008 00:25
22 lines
1915 bytes
1915 bytes
"Asger Joergensen" <junk@Asger-P.dk> wrote in message
news:MPG.221b003de228cd89989a60@newsgroups.borland.com...
> No doubt that You are right as usual, but 'cannot' might be a
> little strong in this case, since the code I posted compiles and
> run just fine in my BCB5.
It is a bug in the compiler. It should be issuing the following error
instead:
"E2459 VCL style classes must be constructed using operator new"
If you create a local variable of calling the method inlined, BCB5 will
issue the error correctly:
char Buf[200];
TClipboard cb; // <-- error
cb.GetTextBuf(Buf, 200);
Gambit
Re: Getting binary data from the clipboard
Author: Remy Lebeau (TeamB)
Date: Tue, 12 Feb 2008 00:29
Date: Tue, 12 Feb 2008 00:29
24 lines
1996 bytes
1996 bytes
"Remy Lebeau (TeamB)" <no.spam@no.spam.com> wrote in message
news:47b0e780$1@newsgroups.borland.com...
> It is a bug in the compiler. It should be issuing the following error
> instead:
>
> "E2459 VCL style classes must be constructed using operator new"
If you try your code in BCB 6, the linker will report "unresolved external"
errors:
char Buf[200];
TClipboard().GetTextBuf(Buf, 200);
[Linker Error] Unresolved external 'Clipbrd::TClipboard::' referenced
from ...
[Linker Error] Unresolved external '__fastcall
Clipbrd::TClipboard::GetTextBuf(char *, int)' referenced from ...
If you change it to a variable, the compiler E2459 error will occur instead.
Gambit
Re: Getting binary data from the clipboard
Author: Asger Joergensen
Date: Tue, 12 Feb 2008 08:02
Date: Tue, 12 Feb 2008 08:02
22 lines
1773 bytes
1773 bytes
Hi Remy Remy Lebeau (TeamB) says: > > "Asger Joergensen" <junk@Asger-P.dk> wrote in message > news:MPG.221b003de228cd89989a60@newsgroups.borland.com... > > > No doubt that You are right as usual, but 'cannot' might be a > > little strong in this case, since the code I posted compiles and > > run just fine in my BCB5. > > It is a bug in the compiler. It should be issuing the following error > instead: > > "E2459 VCL style classes must be constructed using operator new" Yeaa, I know that one..;-) Thanks for explaining. Kind regards Asger
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads