Article View: borland.public.cppbuilder.nativeapi
Article #8806Re: WM_COPYDATA problem
From: Sam S. Firouz
Date: Fri, 17 Sep 2004 14:40
Date: Fri, 17 Sep 2004 14:40
43 lines
2447 bytes
2447 bytes
I think your problem is in this line: cds.lpData=AnsiStringToSend.c_str(); AnsiString does some memory management in the background and might change the memory location of the data. I believe I have seen some reference in the help files about this. what c_str() returns is only valid if it is passed to another function on the stack. BCB does not guarantee the pointer returned by c_str() will remain valid after that. please look at the example in the help file for c_str() function Sam "Boba" <Boba@somewhere.world> wrote in message news:4147428c@newsgroups.borland.com... > Hallo, > I use the WM_COPYDATA message to send the AnsiString content > between TApplications. Once in a while (I'd say <10% cases) > the string will arrive corrupt at the end. Are there any > special considerations regarding usage of this message for > data exchange? or should I ask in .components.using NG ? > Here's what I do: > > //sending: > COPYDATASTRUCT cds; > cds.dwData=1;//number of strings to be sent > cds.cbData=AnsiStringToSend.Length();//<1024 > cds.lpData=AnsiStringToSend.c_str(); > ::SendMessage(hWndOfReceiver,WM_COPYDATA, 0,(LPARAM)&cds); > //reciving: > char buff[1024]; > ::ZeroMemory(buff,sizeof(buff)); > ::CopyMemory(buff,Msg.CopyDataStruct->lpData,Msg.CopyDataStruct->cbData); > //where Msg is of ref. to TWMCopyData type > AnsiString s=AnsiString(buff); > ShowMessage(s);//some strings get corrupt. Why? > > Please help. Boba. > > >
Technical Details
Message-ID:
<414af606$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.maxwell.syr.edu!fr.ip.ndsoftware.net!newsfeed.freenet.de!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 Reply-To: "Sam S. Firouz" <sfirouz@Hotmail.com> From: "Sam S. Firouz" <sfirouz@Hotmail.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <4147428c@newsgroups.borland.com> Subject: Re: WM_COPYDATA problem Date: Fri, 17 Sep 2004 10:40:50 -0400 Lines: 45 Organization: P.T.F.S. X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1409 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409 NNTP-Posting-Host: 132.250.186.165 Message-ID: <414af606$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1095431686 132.250.186.165 (17 Sep 2004 07:34:46 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.maxwell.syr.edu!fr.ip.ndsoftware.net!newsfeed.freenet.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail