What is the max length for a string sent through WM_COPYDATA

  • Follow


I=B4ve written a small application to monitor another application of
mine.
The small one has only one edit control and it does nothing but wait
for WM_COPYDATA messages and display whatever it receives in plain
text inside the edit.
The big one sends frequent WM_COPYDATA messages to the small one,
containing in plain text some data.
If the data exceeds a given size (no clue how much, maybe about 10K)
the message doesn=B4t go through anymore, the small application doesn=B4t
receive anything at all.
So I=B4m wondering, since the size of the message is sent in
DWORD .cbData, is there a maximum of characters for this message other
than the max value of DWORD?
0
Reply Piranha 11/7/2010 12:30:51 PM

On Sun, 7 Nov 2010 04:30:51 -0800 (PST), Piranha
<eu_piranha@gmx.net> wrote:

>I=B4ve written a small application to monitor another application of
>mine.
>The small one has only one edit control and it does nothing but wait
>for WM_COPYDATA messages and display whatever it receives in plain
>text inside the edit.
>The big one sends frequent WM_COPYDATA messages to the small one,
>containing in plain text some data.
>If the data exceeds a given size (no clue how much, maybe about 10K)
>the message doesn=B4t go through anymore, the small application doesn=B4t
>receive anything at all.
>So I=B4m wondering, since the size of the message is sent in
>DWORD .cbData, is there a maximum of characters for this message other
>than the max value of DWORD?

From what I've read, the size is limited only by the max
value of cbData (4GB).  But I've never needed to send any
more than a KB or so at at time.

I assume since you've gotten this far, you know that the
data in the COPYDATASTRUCT doesn't persist... you have to
grab it at the time you get the WM_COPYDATA.  Other than
that, can't think what would limit the size.

Best regards,


Bob Masta
 
              DAQARTA  v5.10
   Data AcQuisition And Real-Time Analysis
              www.daqarta.com
Scope, Spectrum, Spectrogram, Sound Level Meter
    Frequency Counter, FREE Signal Generator
           Pitch Track, Pitch-to-MIDI 
         DaqMusic - FREE MUSIC, Forever!
             (Some assembly required)
     Science (and fun!) with your sound card!
0
Reply N0Spam 11/7/2010 12:46:12 PM


On 7 Nov., 13:46, N0S...@daqarta.com (Bob Masta) wrote:
> On Sun, 7 Nov 2010 04:30:51 -0800 (PST), Piranha
>
> <eu_pira...@gmx.net> wrote:
> >I=3DB4ve written a small application to monitor another application of
> >mine.
> >The small one has only one edit control and it does nothing but wait
> >for WM_COPYDATA messages and display whatever it receives in plain
> >text inside the edit.
> >The big one sends frequent WM_COPYDATA messages to the small one,
> >containing in plain text some data.
> >If the data exceeds a given size (no clue how much, maybe about 10K)
> >the message doesn=3DB4t go through anymore, the small application doesn=
=3DB4t
> >receive anything at all.
> >So I=3DB4m wondering, since the size of the message is sent in
> >DWORD .cbData, is there a maximum of characters for this message other
> >than the max value of DWORD?
>
> From what I've read, the size is limited only by the max
> value of cbData (4GB). =A0But I've never needed to send any
> more than a KB or so at at time.
>
> I assume since you've gotten this far, you know that the
> data in the COPYDATASTRUCT doesn't persist... you have to
> grab it at the time you get the WM_COPYDATA. =A0Other than
> that, can't think what would limit the size.
>
> Best regards,
>
> Bob Masta

Sure, I grab the data and copy it into a string first thing upon
arrival, problem is, there=B4s nothing arriving if the string is longer
than maybe 10K.
0
Reply Piranha 11/7/2010 1:49:25 PM

On 07/11/2010 12:30, Piranha wrote:
> I�ve written a small application to monitor another application of
> mine.
> The small one has only one edit control and it does nothing but wait
> for WM_COPYDATA messages and display whatever it receives in plain
> text inside the edit.
> The big one sends frequent WM_COPYDATA messages to the small one,
> containing in plain text some data.
> If the data exceeds a given size (no clue how much, maybe about 10K)
> the message doesn�t go through anymore, the small application doesn�t
> receive anything at all.
> So I�m wondering, since the size of the message is sent in
> DWORD .cbData, is there a maximum of characters for this message other
> than the max value of DWORD?

I've successfully passed many KB of data (bitmap info structure and 
data) with no problems.

-- 
Dee Earley (dee.earley@icode.co.uk)
i-Catcher Development Team

iCode Systems

(Replies direct to my email address will be ignored.
Please reply to the group.)
0
Reply Dee 11/8/2010 9:41:13 AM

On 07/11/2010 13:49, Piranha wrote:
> Sure, I grab the data and copy it into a string first thing upon
> arrival, problem is, there�s nothing arriving if the string is longer
> than maybe 10K.

Usual reply of "show us the code" :)
Checking for any errors/return values from sending is also a good idea.

-- 
Dee Earley (dee.earley@icode.co.uk)
i-Catcher Development Team

iCode Systems

(Replies direct to my email address will be ignored.
Please reply to the group.)
0
Reply Dee 11/8/2010 9:42:55 AM

On 8 Nov., 10:42, Dee Earley <dee.ear...@icode.co.uk> wrote:
> On 07/11/2010 13:49, Piranha wrote:
>
> > Sure, I grab the data and copy it into a string first thing upon
> > arrival, problem is, there=B4s nothing arriving if the string is longer
> > than maybe 10K.
>
> Usual reply of "show us the code" :)
> Checking for any errors/return values from sending is also a good idea.
>
> --
> Dee Earley (dee.ear...@icode.co.uk)
> i-Catcher Development Team
>
> iCode Systems
>
> (Replies direct to my email address will be ignored.
> Please reply to the group.)

Sender:

void SendToDisplay(string mytext)
{
COPYDATASTRUCT cd;
cd.dwData =3D 1;
cd.cbData =3D static_cast<DWORD>(mytext.size()) + 1;
cd.lpData =3D const_cast<char *>(mytext.c_str());
SendMessage(FindWindow("DisplayWindow",0),WM_COPYDATA,(WPARAM)hwnd,
(LPARAM)&cd);
return;
}

Receiver:

case WM_COPYDATA:
{
PCOPYDATASTRUCT cd =3D (PCOPYDATASTRUCT)lParam;
char * Temp =3D (LPSTR)cd->lpData;
string received(Temp);
// call a function that updates the edit control
ExecCopydata(received);
}
break;

For testing purposes I=B4ve put a MessageBox at the receiver end:
case WM_COPYDATA:
{
MessageBox(0,"received a message","CopyData",MB_OK);
....

If the string exceeds a given size, the MessageBox doesn=B4t pop up.
There is no error message whatsoever, any message sent before or after
will show up correct.

i.e.

string SomeLongString =3D "..."; // some 10KB of text
SendToDisplay("Sending now");
SendToDisplay(SomeLongString);
SendToDisplay("Sending done");

Will show up at the receiving end as

Sending now
Sending done

without a trace of the long string.
0
Reply Piranha 11/8/2010 3:19:16 PM

On Mon, 8 Nov 2010 07:19:16 -0800 (PST), Piranha
<eu_piranha@gmx.net> wrote:

>On 8 Nov., 10:42, Dee Earley <dee.ear...@icode.co.uk> wrote:
>> On 07/11/2010 13:49, Piranha wrote:
>>
>> > Sure, I grab the data and copy it into a string first thing upon
>> > arrival, problem is, there=B4s nothing arriving if the string is longer
>> > than maybe 10K.
>>
>> Usual reply of "show us the code" :)
>> Checking for any errors/return values from sending is also a good idea.
>>
>> --
>> Dee Earley (dee.ear...@icode.co.uk)
>> i-Catcher Development Team
>>
>> iCode Systems
>>
>> (Replies direct to my email address will be ignored.
>> Please reply to the group.)
>
>Sender:
>
>void SendToDisplay(string mytext)
>{
>COPYDATASTRUCT cd;
>cd.dwData =3D 1;
>cd.cbData =3D static_cast<DWORD>(mytext.size()) + 1;
>cd.lpData =3D const_cast<char *>(mytext.c_str());
>SendMessage(FindWindow("DisplayWindow",0),WM_COPYDATA,(WPARAM)hwnd,
>(LPARAM)&cd);
>return;
>}
>
>Receiver:
>
>case WM_COPYDATA:
>{
>PCOPYDATASTRUCT cd =3D (PCOPYDATASTRUCT)lParam;
>char * Temp =3D (LPSTR)cd->lpData;
>string received(Temp);
>// call a function that updates the edit control
>ExecCopydata(received);
>}
>break;
>
>For testing purposes I=B4ve put a MessageBox at the receiver end:
>case WM_COPYDATA:
>{
>MessageBox(0,"received a message","CopyData",MB_OK);
>...
>
>If the string exceeds a given size, the MessageBox doesn=B4t pop up.
>There is no error message whatsoever, any message sent before or after
>will show up correct.
>
>i.e.
>
>string SomeLongString =3D "..."; // some 10KB of text
>SendToDisplay("Sending now");
>SendToDisplay(SomeLongString);
>SendToDisplay("Sending done");
>
>Will show up at the receiving end as
>
>Sending now
>Sending done
>
>without a trace of the long string.

Hmm, I've never tried to show a super-long string with
MessageBox... are you sure it can handle that?  Suppose you
copy the data to a buffer first, then either report the size
of the copy, or send only (say) the last hundred bytes to
the MessageBox.

Best regards,


Bob Masta
 
              DAQARTA  v5.10
   Data AcQuisition And Real-Time Analysis
              www.daqarta.com
Scope, Spectrum, Spectrogram, Sound Level Meter
    Frequency Counter, FREE Signal Generator
           Pitch Track, Pitch-to-MIDI 
         DaqMusic - FREE MUSIC, Forever!
             (Some assembly required)
     Science (and fun!) with your sound card!
0
Reply N0Spam 11/9/2010 1:09:41 PM

On 9 Nov., 14:09, N0S...@daqarta.com (Bob Masta) wrote:
> On Mon, 8 Nov 2010 07:19:16 -0800 (PST), Piranha
>
>
>
>
>
> <eu_pira...@gmx.net> wrote:
> >On 8 Nov., 10:42, Dee Earley <dee.ear...@icode.co.uk> wrote:
> >> On 07/11/2010 13:49, Piranha wrote:
>
> >> > Sure, I grab the data and copy it into a string first thing upon
> >> > arrival, problem is, there=3DB4s nothing arriving if the string is l=
onger
> >> > than maybe 10K.
>
> >> Usual reply of "show us the code" :)
> >> Checking for any errors/return values from sending is also a good idea=
..
>
> >> --
> >> Dee Earley (dee.ear...@icode.co.uk)
> >> i-Catcher Development Team
>
> >> iCode Systems
>
> >> (Replies direct to my email address will be ignored.
> >> Please reply to the group.)
>
> >Sender:
>
> >void SendToDisplay(string mytext)
> >{
> >COPYDATASTRUCT cd;
> >cd.dwData =3D3D 1;
> >cd.cbData =3D3D static_cast<DWORD>(mytext.size()) + 1;
> >cd.lpData =3D3D const_cast<char *>(mytext.c_str());
> >SendMessage(FindWindow("DisplayWindow",0),WM_COPYDATA,(WPARAM)hwnd,
> >(LPARAM)&cd);
> >return;
> >}
>
> >Receiver:
>
> >case WM_COPYDATA:
> >{
> >PCOPYDATASTRUCT cd =3D3D (PCOPYDATASTRUCT)lParam;
> >char * Temp =3D3D (LPSTR)cd->lpData;
> >string received(Temp);
> >// call a function that updates the edit control
> >ExecCopydata(received);
> >}
> >break;
>
> >For testing purposes I=3DB4ve put a MessageBox at the receiver end:
> >case WM_COPYDATA:
> >{
> >MessageBox(0,"received a message","CopyData",MB_OK);
> >...
>
> >If the string exceeds a given size, the MessageBox doesn=3DB4t pop up.
> >There is no error message whatsoever, any message sent before or after
> >will show up correct.
>
> >i.e.
>
> >string SomeLongString =3D3D "..."; // some 10KB of text
> >SendToDisplay("Sending now");
> >SendToDisplay(SomeLongString);
> >SendToDisplay("Sending done");
>
> >Will show up at the receiving end as
>
> >Sending now
> >Sending done
>
> >without a trace of the long string.
>
> Hmm, I've never tried to show a super-long string with
> MessageBox... are you sure it can handle that? =A0Suppose you
> copy the data to a buffer first, then either report the size
> of the copy, or send only (say) the last hundred bytes to
> the MessageBox.
>
> Best regards,
>
> Bob Masta
>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 DAQARTA =A0v5.10
> =A0 =A0Data AcQuisition And Real-Time Analysis
> =A0 =A0 =A0 =A0 =A0 =A0 =A0www.daqarta.com
> Scope, Spectrum, Spectrogram, Sound Level Meter
> =A0 =A0 Frequency Counter, FREE Signal Generator
> =A0 =A0 =A0 =A0 =A0 =A0Pitch Track, Pitch-to-MIDI
> =A0 =A0 =A0 =A0 =A0DaqMusic - FREE MUSIC, Forever!
> =A0 =A0 =A0 =A0 =A0 =A0 =A0(Some assembly required)
> =A0 =A0 =A0Science (and fun!) with your sound card!- Zitierten Text ausbl=
enden -
>
> - Zitierten Text anzeigen -

Display it in a MessageBox instead of the edit cotrol wouldn=B4t be a
problem, I=B4ve had MessageBoxes filling the entire screen at 1920x1200
resolution.
Problem is, the MessageBox should popup only the short Message
"CopyData" just to indicate a COPYDATA message was received, yet it
doesn=B4t pop up at all if the string is too long, which would indicate,
there was no COPYDATA message received.
At same time on the other side, SendMessage() doesn=B4t return any error
either.

In short, the message gets lost somewhere on the way, without any
indication why.

0
Reply Piranha 11/9/2010 4:09:18 PM

> Problem is, the MessageBox should popup only the short Message
> "CopyData" just to indicate a COPYDATA message was received, yet it
> doesn=B4t pop up at all if the string is too long, which would indicate,
> there was no COPYDATA message received.
> At same time on the other side, SendMessage() doesn=B4t return any error
> either.

Why don't you, just for the sake of experiment, change the MessageBox
call to display a short static string rather than the received data.
Then if it still doesn't pop up you would definitely know that it is
the WM_COPYDATA that's failing, and not the MessageBox call.
0
Reply jon 11/9/2010 7:50:37 PM

On 9 Nov., 20:50, jon <jpot...@gmail.com> wrote:
> > Problem is, the MessageBox should popup only the short Message
> > "CopyData" just to indicate a COPYDATA message was received, yet it
> > doesn=B4t pop up at all if the string is too long, which would indicate=
,
> > there was no COPYDATA message received.
> > At same time on the other side, SendMessage() doesn=B4t return any erro=
r
> > either.
>
> Why don't you, just for the sake of experiment, change the MessageBox
> call to display a short static string rather than the received data.
> Then if it still doesn't pop up you would definitely know that it is
> the WM_COPYDATA that's failing, and not the MessageBox call.

That IS what I=B4m doing, the MessageBox displays the header "Received"
and the text "CopyData", thats 8 + 8 byte, nothing more.
0
Reply Piranha 11/10/2010 10:57:03 AM

Am Wed, 10 Nov 2010 02:57:03 -0800 (PST) schrieb Piranha:
> That IS what I�m doing, the MessageBox displays the header "Received"
> and the text "CopyData", thats 8 + 8 byte, nothing more.

This means your receiver gets WM_COPYDATA, but not the string data?
What is the received value of cbData, and what is in the memory lpData
points to?

I just tried it with a 128 K ANSI string on Vista, and the receiver got the
complete string data.

> void SendToDisplay(string mytext)

Usually large objects are passed by reference to avoid the copy.

What is mytext.c_str() here at this point before sending?

> {
> COPYDATASTRUCT cd;
> cd.dwData = 1;
> cd.cbData = static_cast<DWORD>(mytext.size()) + 1;
> cd.lpData = const_cast<char *>(mytext.c_str());
> SendMessage(FindWindow("DisplayWindow",0),WM_COPYDATA,(WPARAM)hwnd,
> (LPARAM)&cd);
> return;
}

Regards,
Friedel
0
Reply Friedel 11/12/2010 8:49:33 AM

On 12 Nov., 09:49, Friedel Jantzen <nospam_...@freenet.de> wrote:
> Am Wed, 10 Nov 2010 02:57:03 -0800 (PST) schrieb Piranha:
>
> > That IS what I m doing, the MessageBox displays the header "Received"
> > and the text "CopyData", thats 8 + 8 byte, nothing more.
>
> This means your receiver gets WM_COPYDATA, but not the string data?

Nope, it means my receiver gets WM_COPYDATA only if the string is
shorter than a given size, if it=B4s longer, the receiver doesn=B4t get
any message, while on the sender end the SendMessage() doesn=B4t return
any error either way.

> What is the received value of cbData, and what is in the memory lpData
> points to?
>

If it goes through, cbData and lpData are correct, otherwise there is
nothing received, therefore I can=B4t check the values either.

> I just tried it with a 128 K ANSI string on Vista, and the receiver got t=
he
> complete string data.
>
> > void SendToDisplay(string mytext)
>
> Usually large objects are passed by reference to avoid the copy.
>

I know, but thats just a matter of style and program performance, for
a basic test it should work either way, copy or pointer.

> What is mytext.c_str() here at this point before sending?
>

Whatever I call the function with, currently it=B4s just for testing, so
I simply hardcode some text into it, i.e.

string MyText =3D "Some String";
SendToDisplay(MyText);

> > {

If I output MyText here, it shows correct.

> > COPYDATASTRUCT cd;
> > cd.dwData =3D 1;
> > cd.cbData =3D static_cast<DWORD>(mytext.size()) + 1;
> > cd.lpData =3D const_cast<char *>(mytext.c_str());
> > SendMessage(FindWindow("DisplayWindow",0),WM_COPYDATA,(WPARAM)hwnd,
> > (LPARAM)&cd);
> > return;
> }
>

I=B4m just lost, it should all be working, yet it doesn=B4t and I really
don=B4t understand, why the receiver shouldn=B4t receive anything at all,
while SendMessage() returns success, especially I can=B4t see, why this
is working up to a given string.size and not with a longer string,
while I=B4m way below the max size.
0
Reply Piranha 11/17/2010 2:21:28 PM

On 17/11/2010 14:21, Piranha wrote:
> On 12 Nov., 09:49, Friedel Jantzen<nospam_...@freenet.de>  wrote:
>> Am Wed, 10 Nov 2010 02:57:03 -0800 (PST) schrieb Piranha:
>>
>>> That IS what I m doing, the MessageBox displays the header "Received"
>>> and the text "CopyData", thats 8 + 8 byte, nothing more.
>>
>> This means your receiver gets WM_COPYDATA, but not the string data?
>
> Nope, it means my receiver gets WM_COPYDATA only if the string is
> shorter than a given size, if it�s longer, the receiver doesn�t get
> any message, while on the sender end the SendMessage() doesn�t return
> any error either way.

Can you find out what this "given size" is?

-- 
Dee Earley (dee.earley@icode.co.uk)
i-Catcher Development Team

iCode Systems

(Replies direct to my email address will be ignored.
Please reply to the group.)
0
Reply Dee 11/18/2010 9:08:09 AM

Am Wed, 17 Nov 2010 06:21:28 -0800 (PST) schrieb Piranha:
....
>>
>>> void SendToDisplay(string mytext)
>>
>> Usually large objects are passed by reference to avoid the copy.
>>
> 
> I know, but thats just a matter of style and program performance, for
> a basic test it should work either way, copy or pointer.

Yes.
But it has not only bad performance, depending on the implementation it
could be a heavy load on the stack.
Another difference is, that the copy will not survive when SendToDisplay
returns.
Perhaps try it with a reference or pointer to see if the problem remains.

....
> don�t understand, why the receiver shouldn�t receive anything at all,
> while SendMessage() returns success, especially I can�t see, why this
> is working up to a given string.size and not with a longer string,
> while I�m way below the max size.

I successfully sent now even a 128 MB string.
Guessing only, perhaps something other is messing up your string object,
before you send it.

Regards,
Friedel
0
Reply Friedel 11/18/2010 10:25:39 AM

On Wed, 17 Nov 2010 06:21:28 -0800 (PST), Piranha
<eu_piranha@gmx.net> wrote:

>On 12 Nov., 09:49, Friedel Jantzen <nospam_...@freenet.de> wrote:
>> Am Wed, 10 Nov 2010 02:57:03 -0800 (PST) schrieb Piranha:
>>
>> > That IS what I m doing, the MessageBox displays the header "Received"
>> > and the text "CopyData", thats 8 + 8 byte, nothing more.
>>
>> This means your receiver gets WM_COPYDATA, but not the string data?
>
>Nope, it means my receiver gets WM_COPYDATA only if the string is
>shorter than a given size, if it=B4s longer, the receiver doesn=B4t get
>any message, while on the sender end the SendMessage() doesn=B4t return
>any error either way.
>
>> What is the received value of cbData, and what is in the memory lpData
>> points to?
>>
>
>If it goes through, cbData and lpData are correct, otherwise there is
>nothing received, therefore I can=B4t check the values either.
>
>> I just tried it with a 128 K ANSI string on Vista, and the receiver got t=
>he
>> complete string data.
>>
>> > void SendToDisplay(string mytext)
>>
>> Usually large objects are passed by reference to avoid the copy.
>>
>
>I know, but thats just a matter of style and program performance, for
>a basic test it should work either way, copy or pointer.

The MSDN instructions for WM_COPYDATA state that:

"The data being passed must not contain pointers or other
references not accessible to the application receiving the
data".

I interpret that to mean that the COPYDATASTRUCT must
include a pointer to the data itself, but other than that
the "not accessible" part is a bit of a mystery.  Normally I
would expect that *nothing* in the sending app would be
accessible to the receiving app, since they are separate
processes.  So WM_COPYDATA must be doing some trick where it
either copies the data to an intermediate buffer, or (more
likely) it locks the sender buffer and remaps its address
until WM_COPYDATA returns.   

The same pointer address can't normally be expected to be
valid in two different processes, so WM_COPYDATA must be
doing something tricky.  We get a hint about that from the
fact  that the receiving process has to grab the actual data
(not just the pointer) before returning from WM_COPYDATA.

So the point of this long-winded ramble is that maybe
WM_COPYDATA is very picky about what the pointer in
COPYDATASTRUCT points to.  As a test, you could try a couple
of different approaches, such as GlobalAlloc or actually
reserving the buffer in the .data or .data? section of your
source code via DB (or whatever your language uses).

Just a thought...


Bob Masta
 
              DAQARTA  v5.10
   Data AcQuisition And Real-Time Analysis
              www.daqarta.com
Scope, Spectrum, Spectrogram, Sound Level Meter
    Frequency Counter, FREE Signal Generator
           Pitch Track, Pitch-to-MIDI 
         DaqMusic - FREE MUSIC, Forever!
             (Some assembly required)
     Science (and fun!) with your sound card!
0
Reply N0Spam 11/18/2010 1:51:02 PM

14 Replies
691 Views

(page loaded in 0.19 seconds)

Similiar Articles:

















7/23/2012 10:36:54 PM


Reply: