Article View: borland.public.cppbuilder.nativeapi
Article #14077Re: Messages between DLL and Application
From: Remy Lebeau (TeamB)
Date: Mon, 25 Aug 2003 23:27
Date: Mon, 25 Aug 2003 23:27
48 lines
2944 bytes
2944 bytes
"Martin C" <martinc@aol.com> wrote in message
news:3f4a98a3@newsgroups.borland.com...
> if(Message.CopyDataStruct->dwData > 0)
You need to use a unique value for dwData. Don't just assume any arbitrary
value. The VCL itself uses WM_COPYDATA for its own internal usage, as may
other windows/components. Your code needs to use its own unique value as
well, and then test for that specific value so that your code knows that it
is really intercepting your WM_COPYDATA message and not someone else's.
> AnsiString
TheRecievedString=reinterpret_cast<char*>(Message.CopyDataStruct->lpData);
You are not taking the cbData value into account at all. You should be
doing that, as that tells you how many bytes are in the lpData. Do this
instead:
char *ptr = reinterpret_cast<char*>(Message.CopyDataStruct->lpData);
AnsiString TheRecievedString(ptr, Message.CopyDataStruct->cbData);
> Memo1->Lines->Add(TheRecievedString.c_str());
You don't need to use c_str() there. TheRecievedString is an AnsiString,
and Add() takes an AnsiString parameter:
Memo1->Lines->Add(TheRecievedString);
> and I really receive the data from the dll, but corrupted at
> the end of each string received...!!
That typically happens if you are not sending the null terminator along with
your string. Your current receiving code is expecting a null terminator to
be present since you are not taking the actual data length into account.
But if you do not actually send the null terminator, then you are going to
get mixed results. So you need to either make sure that you always send a
null terminator with your string data, or else utilize the cbData value, or
better yet, a combination of both.
Gambit
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.512 / Virus Database: 309 - Release Date: 8/19/03
Technical Details
Message-ID:
<3f4a9b76$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-05!sn-xit-09!supernews.com!news.maxwell.syr.edu!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mailReferences:
<3f4a7447@newsgroups.borland.com> <3f4a770d$1@newsgroups.borland.com> <3f4a98a3@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,64add9c25ea7ead X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2003-08-25 16:32:39 PST From: "Remy Lebeau \(TeamB\)" <gambit47@yahoo.com> Newsgroups: borland.public.cppbuilder.nativeapi References: <3f4a7447@newsgroups.borland.com> <3f4a770d$1@newsgroups.borland.com> <3f4a98a3@newsgroups.borland.com> Subject: Re: Messages between DLL and Application Date: Mon, 25 Aug 2003 16:27:50 -0700 Lines: 50 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 NNTP-Posting-Host: 207.175.226.26 Message-ID: <3f4a9b76$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1061854070 207.175.226.26 (25 Aug 2003 16:27:50 -0700) Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-05!sn-xit-09!supernews.com!news.maxwell.syr.edu!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail