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