Problem with WM_COPYDATA 
Author Message
 Problem with WM_COPYDATA

Hi All,

Trying to communication from a worker thread to a UI thread using
WM_COPYDATA.  The following is the code in the worker thread:

TypeDef Void* Foo;
int Count = 32;
CopyDataStruct cds;

Foo *test = new Foo[32];

{
I fill in the Foo array here

Quote:
}

cds.cbData = sizeof(Foo);
cds.lpData = test;
cds.dwData = Count;

Use SendMessage to send the message here.

In the OnCopyData method in the receiving thread is the following code:

Foo *test2 = (Foo*)pCopyDataStruct->lpdata;

If I increment through <test2> to retreive the values I have sent the first
value is correct but everything else is garbage.  Where am I going wrong?
Is this a limitation on WM_COPYDATA? What others ways could I get the same
information in the array across without using multiple messages?

Thanks,

Dan Pearce



Mon, 02 Jun 2003 13:19:16 GMT  
 Problem with WM_COPYDATA
One apparent problem is that cdw.cbData is set to 4 (sizeof(Foo)) when it
should be set to 32 (Count).  You have effectively told WM_COPYDATA that you
only want to transfer 4 bytes of data.  Keep in mind that the data is copied
from one address space to another.  The pointer you have provided (lpData)
is not passed across.  Rather that data pointed to by lpData is copied to
the receiving application's address space.  The amount of data copied is
determined by cbData.  The dwData member is typically used to transfer a
small amount of data, fo example a "hint" of what type of data is being
passed in lpData.

TFM3

Note: Spam-resistant e-mail address

Quote:

> Hi All,

> Trying to communication from a worker thread to a UI thread using
> WM_COPYDATA.  The following is the code in the worker thread:

> TypeDef Void* Foo;
> int Count = 32;
> CopyDataStruct cds;

> Foo *test = new Foo[32];

> {
> I fill in the Foo array here
> }

> cds.cbData = sizeof(Foo);
> cds.lpData = test;
> cds.dwData = Count;

> Use SendMessage to send the message here.

> In the OnCopyData method in the receiving thread is the following code:

> Foo *test2 = (Foo*)pCopyDataStruct->lpdata;

> If I increment through <test2> to retreive the values I have sent the
first
> value is correct but everything else is garbage.  Where am I going wrong?
> Is this a limitation on WM_COPYDATA? What others ways could I get the same
> information in the array across without using multiple messages?

> Thanks,

> Dan Pearce



Mon, 02 Jun 2003 13:48:40 GMT  
 Problem with WM_COPYDATA
If the worker thread and UI thread are in the same process, there is
no reason to use WM_COPYDATA at all. Inside a process, you can use
WM_APP + x (or a registered message) and pass a pointer in WPARAM or
LPARAM.

Quote:

>Hi All,

>Trying to communication from a worker thread to a UI thread using
>WM_COPYDATA.  The following is the code in the worker thread:

>TypeDef Void* Foo;
>int Count = 32;
>CopyDataStruct cds;

>Foo *test = new Foo[32];

>{
>I fill in the Foo array here
>}

>cds.cbData = sizeof(Foo);
>cds.lpData = test;
>cds.dwData = Count;

>Use SendMessage to send the message here.

>In the OnCopyData method in the receiving thread is the following code:

>Foo *test2 = (Foo*)pCopyDataStruct->lpdata;

>If I increment through <test2> to retreive the values I have sent the first
>value is correct but everything else is garbage.  Where am I going wrong?
>Is this a limitation on WM_COPYDATA? What others ways could I get the same
>information in the array across without using multiple messages?

>Thanks,

>Dan Pearce

Don Grasberger

(remove --- from address to e-mail)



Mon, 02 Jun 2003 22:43:30 GMT  
 Problem with WM_COPYDATA

Quote:

>If the worker thread and UI thread are in the same process, there is
>no reason to use WM_COPYDATA at all. Inside a process, you can use
>WM_APP + x (or a registered message) and pass a pointer in WPARAM or
>LPARAM.

He'd still have to wrap a critical section around any access though,
if using a shared area.

--
Bob Moore [WinSDK MVP]
http://www.mooremvp.freeserve.co.uk/
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Do not reply via email unless specifically requested to do so.
Unsolicited email is NOT welcome and will go unanswered.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



Tue, 03 Jun 2003 06:14:00 GMT  
 Problem with WM_COPYDATA
On Thu, 14 Dec 2000 22:14:00 +0000, Bob Moore

Quote:


>>If the worker thread and UI thread are in the same process, there is
>>no reason to use WM_COPYDATA at all. Inside a process, you can use
>>WM_APP + x (or a registered message) and pass a pointer in WPARAM or
>>LPARAM.

>He'd still have to wrap a critical section around any access though,
>if using a shared area.

Well, not really. SendMessage() won't return until the UI thread has
processed the message, so there's no synchronization issues with the
thread sending the message.  If there are more than those 2 threads
accessing the object, then something like a CS will be necessary. Of
course, if Dan wants to use PostMessage(), more complexities arise
concerning the lifetime of the pointed to object as well as
synchronization.

Don Grasberger

(remove --- from address to e-mail)



Tue, 03 Jun 2003 22:24:22 GMT  
 Problem with WM_COPYDATA

Quote:

>SendMessage() won't return until the UI thread has
>processed the message, so there's no synchronization issues with the
>thread sending the message

Duh. Must engage brain before posting. Sorry.

--
Bob Moore [WinSDK MVP]
http://www.mooremvp.freeserve.co.uk/
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Do not reply via email unless specifically requested to do so.
Unsolicited email is NOT welcome and will go unanswered.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



Wed, 04 Jun 2003 07:13:40 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Marshaling problem using WM_COPYDATA and byte[]

2. Still got problems with WM_COPYDATA message !

3. I am having problem sending WM_COPYDATA message to a 16bit app.

4. WM_COPYDATA Problems (urgent) ...

5. Problem in sending WM_COPYDATA message

6. WM_COPYDATA can I do it in C#?

7. WM_COPYDATA

8. how to use WM_COPYDATA ?

9. SendMessage/WM_COPYDATA

10. Weird WM_COPYDATA behaviour

11. WM_COPYDATA

12. WM_PASTE and WM_COPYDATA

 

 
Powered by phpBB® Forum Software