🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Communication between two applications

#8416
From: Stefano Bonifazi
Date: Sat, 30 Oct 2004 10:30
50 lines
3365 bytes
Hi again!
 Sorry but I have to post an errata corrige and some notes:

> SendMessage(pReceiveAppHandle, //the pointer to the receiver application
we
> mention above!
>                       WM_COPYDATA,  //the kind of message we're going to
> send
>                       (WPARAM)&cd,      //U send only the pointer to the
> struct, it would be a burden for windows to send all the stuff
>                       (LPARAM)Handle);  //U may find useful to receive the
> sender application Handle from the receiver application, this parameter
> allows that!

This seems to work, but the correct way is with the second and third
parameter exchanged!
 SendMessage(pReceiveAppHandle, //the pointer to the receiver application we
mention above!
                       WM_COPYDATA,  //the kind of message we're going to
send
                       (WPARAM)Handle,  //U may find useful to receive the
sender application Handle from the receiver application, this parameter
allows that!
                       (LPARAM)&cd);      //U send only the pointer to the
struct, it would be a burden for windows to send all the stuff
So You would also need to change
COPYDATASTRUCT *pCD = (COPYDATASTRUCT *)Message.WParam;
with COPYDATASTRUCT *pCD = (COPYDATASTRUCT *)Message.LParam; in the message
handler!

Notes:
1) As the great Mr.Gambit teaches us all the dwData member of the
COPYDATASTRUCT should be used to distinguish the different COPYDATA messages
... I only used it to speed the things up , but avoid that way ... You
should use the proper data member instead! See WM_COPYDATA documentation!
2) I told You that is quite easy to get the handle of the receiver
application ... well if You spawn it from the sender application You can get
it easily, but if not then ... I failed to get it with FindWindow, or better
I failed to get an handle to the MainForm of Your receiver application whose
message handler I wrote belongs to ... i only could get the Application
handle, but its message handler (got setting Application->OnMessage) does
not handle messages sent with SendMessage (and You need to use it with
WM_COPYDATA).
My workaround has been to get that handle by enumerating all the top level
windows by using EnumWindows and checking for the proper Window Class inside
its callback (for me "TForm2") ... Let me know if U need help with that or
follow the thread I'm going to post!:)

 See Ya!
Stefano B.
Technical Details
Message-ID: <41836d35@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <41824B51.804A82A5@ulb.ac.be> <41827ab9@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,e336fb05149be70e
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Stefano Bonifazi" <stefboombastic@tele2.it>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <41824B51.804A82A5@ulb.ac.be> <41827ab9@newsgroups.borland.com>
Subject: Re: Communication between two applications
Date: Sat, 30 Oct 2004 12:30:12 +0200
Lines: 52
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
NNTP-Posting-Host: 212.141.199.222
Message-ID: <41836d35@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1099132213 212.141.199.222 (30 Oct 2004 03:30:13 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail