Article View: borland.public.cppbuilder.nativeapi
Article #8796Re: WM_COPYDATA problem
From: Remy Lebeau [TeamB]
Date: Thu, 16 Sep 2004 04:30
Date: Thu, 16 Sep 2004 04:30
30 lines
2450 bytes
2450 bytes
"Boba" <Boba@somewhere.world> wrote:
>COPYDATASTRUCT cds;
>cds.dwData=1;//number of strings to be sent
You are misusing the COPYDATASTRUCT structure. You should not be using the dwData value that way. Yes, it is an arbitrary 32-bit application-defined value - however - it is commonly used as a unique identifer instead. WM_COPYDATA is so commonly used, even by the VCL itself, that you should assign your own unique value to dwData to help differentiate between your own WM_COPYDATA messages and those that are actually meant for other windows, which you should ignore. If you need to specify how many strings are in the data, then you should allocate some extra memory and put the count inside the data itself instead of in the dwData value.
>cds.cbData=AnsiStringToSend.Length();//<1024
>cds.lpData=AnsiStringToSend.c_str();
>::SendMessage(hWndOfReceiver,WM_COPYDATA, 0,(LPARAM)&cds);
The only way that code can fail is if the source AnsiString is not valid to begin with, or if it is being altered between the time c_str() is called and WM_COPYDATA is sent.
>char buff[1024];
>::ZeroMemory(buff,sizeof(buff));
>::CopyMemory(buff,Msg.CopyDataStruct->lpData,Msg.CopyDataStruct->cbData);
You don't need a temporary buffer. You can read into AnsiString directly, ie:
AnsiString s;
s.SetLength(Msg.CopyDataStruct->cbData);
::CopyMemory(s.c_str(), Msg.CopyDataStruct->lpData, Msg.CopyDataStruct->cbData);
Alternatively:
AnsiString s((char*)Msg.CopyDataStruct->lpData, Msg.CopyDataStruct->cbData);
Gambit
Technical Details
Message-ID:
<414916f7$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!proxad.net!fr.ip.ndsoftware.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<4147428c@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,2368611c57840a13 X-Google-Attributes: gid10cc67,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Remy Lebeau [TeamB]" <gambit47_no_spam@yahoo_no_spam.com> Sender: "Remy Lebeau [TeamB]" <gambit47_no_spam@yahoo_no_spam.com> Reply-To: "Remy Lebeau [TeamB]" <gambit47_no_spam@yahoo_no_spam.com> Subject: Re: WM_COPYDATA problem Newsgroups: borland.public.cppbuilder.nativeapi X-User-Info: 206.107.212.103 References: <4147428c@newsgroups.borland.com> NNTP-Posting-Host: 207.105.83.66 Message-ID: <414916f7$1@newsgroups.borland.com> Date: 15 Sep 2004 21:30:47 -0700 X-Trace: newsgroups.borland.com 1095309047 207.105.83.66 (15 Sep 2004 21:30:47 -0700) Lines: 30 Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!proxad.net!fr.ip.ndsoftware.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail