🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #8486

Re: SendMessage problem

#8486
From: Ray
Date: Mon, 18 Oct 2004 16:34
129 lines
4197 bytes
Hi Ed

Noticed WM_COPYDATA but didn't see why I needed it. Thanks for explaining. 
But still having problems

In the sender application (launched by the receiver with Handles and msg 
values sent in the command line) I now have

in the constructor

cds=new COPYDATASTRUCT;

cds->cbData=100*sizeof(short);

then in the data sending part

static unsigned short tempbuffer[200];

memcpy(&tempbuffer, buffptr,100*sizeof(short)); //buffptr points to the 
source data

cds->lpData=(void*)tempbuffer;

Debug<<*tempbuffer<<" "<<*(tempbuffer+1)<<" "<<*(tempbuffer+2)<<endl;

SendMessage(myHandle,mymsg,0,(LPARAM)&cds);

I check on the first three data values with the Debug file

In the receiver I have a response table which invokes

LRESULT CmBufferDone(WPARAM ident,LPARAM buff)

{

COPYDATASTRUCT* pDS;

pDS=(COPYDATASTRUCT*)(&buff);

static unsigned short tempbuffer[200];

memcpy(&tempbuffer, (unsigned short*)(pDS->lpData),100*sizeof(short));

Debug<<*tempbuffer<<" "<<*(tempbuffer+1)<<" "<<*(tempbuffer+2)<<endl;

}

When I run the two aplications, I now get columns of 50307 23832 21955

in the receiver, whereas I am sending 2048 2047 2048.

So I am still going wrong?

Ray











"Ed Mulroy [TeamB]" <dont_email_me@invalid.com> wrote in message 
news:4173b404$1@newsgroups.borland.com...
> As I read it you are doing this:
>
> Program A
>  fills a buffer with data
>  sends a message to Program B with the address of the data
>
> Doing it that way is documented to have a problem.  The programs under 
> Windows use virtual memory, and the numeric value of an address is unique 
> to the program using it so will not be valid if another program uses it.
>
> A method provided for doing what you describe is to use the WM_COPYDATA 
> message.  Upon seeing that message Windows arranges for the receiver to be 
> given an address in its virtual memory space which points a data area 
> containing what you sent.
>
> Look up the message WM_COPYDATA in the Windows help and I think your 
> problem will be solved.
>
> .  Ed
>
>> Ray wrote in message
>> news:4173ab7d@newsgroups.borland.com...
>> Hi
>>
>> I am trying to send data between two applications using windows messages. 
>> For the purposes of testing I have
>>
>> In the sender application (launched by the receiver with Handles and msg 
>> values sent in the command line) I have
>>
>>   static unsigned short tempbuffer[200];
>>
>>   memcpy(&tempbuffer, buffptr,100*sizeof(short)); //buffptr points to the 
>> source data
>>
>>   Debug<<*tempbuffer<<" "<<*(tempbuffer+1)<<" "
>> <<*(tempbuffer+2)<<endl;
>>
>>   SendMessage(myHandle,mymsg,0,(LPARAM)&tempbuffer);
>>
>> I check on the first three data values with the Debug file
>>
>> In the receiver I have a response table which invokes
>>
>>   LRESULT CmBufferDone(WPARAM ident,LPARAM buff)
>>
>>   {
>>
>>   static unsigned short tempbuffer[200];
>>
>>   memcpy(&tempbuffer, (unsigned short*)&buff,100*
>> sizeof(short));
>>
>>   Debug<<*tempbuffer<<" "<<*(tempbuffer+1)<<" "
>> <<*(tempbuffer+2)<<endl;
>>
>>   }
>>
>> When I run the two aplications, I get columns of 3672 74 64292 in the 
>> receiver, whereas I am sending 2048 2047 2048. Where am I going wrong?
>
> 
Technical Details
Message-ID: <4173f0a3@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!logbridge.uoregon.edu!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail
References: <4173ab7d@newsgroups.borland.com> <4173b404$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,f5a1aef685366ed1
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Ray" <someone@someisp.net>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <4173ab7d@newsgroups.borland.com> <4173b404$1@newsgroups.borland.com>
Subject: Re: SendMessage problem
Date: Mon, 18 Oct 2004 17:34:40 +0100
Lines: 131
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
X-RFC2646: Format=Flowed; Response
NNTP-Posting-Host: 81.78.59.158
Message-ID: <4173f0a3@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1098117283 81.78.59.158 (18 Oct 2004 09:34:43 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!logbridge.uoregon.edu!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail