🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Communication between two applications

#8411
From: Stefano Bonifazi
Date: Fri, 29 Oct 2004 17:15
82 lines
4112 bytes
Hi Christophe,
 There are different ways and strategies to exchange data between
applications, but if U write both applications, things are quite simple!
Well if U only need to exchange a simple character the messages can be ok...
 In the sender application get a pointer to the receiver application Handle
(ex. by using FindWindow ... ) ... say it pReceiveAppHandle

 char YourChar='c'; //change it with the character U need :)

 COPYDATASTRUCT cd; //this struct can hold bigger pieces of data, but beware
of not copying pointers, Your applications run on different  address spaces
so they would be useless!!

 ZeroMemory(&cd,sizeof(cd)); //always keep things clean :)
 cd.dwData=int(YourChar); //we only need a character so use this trick, get
the ordinal number of the char by casting it to a int :-)
//here the function U need simple not?
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!

Now come to the receiver application:
There are several ways to manage Application Messagges ... I'll opt for
overriding the Form Messages Handler:
In the header place this function declaration:
  void __fastcall WndProc(Messages::TMessage &Message);

In the C++ file implement it:

void __fastcall TForm1::WndProc(Messages::TMessage &Message)
{

        if(Message.Msg == WM_COPYDATA   ) //Remember this is the kind of
message we used to send data:)
        {


           COPYDATASTRUCT *pCD = (COPYDATASTRUCT *)Message.WParam;
//Remember we only sent the pointer to that struct
           ShowMessage("Character arrived: "+AnsiString(char(pCD->dwData)));
//We have to reverse the trick used to send a character through a integer,
just cast back the ordinal number of Your character to a char

                return;
        }

        TForm::WndProc(Message); // We only need to handle the  WM_COPYDATA
message type, so leave the application to handle all the ramain.N.B. If U
don't do this no message (there are tons of messages example the ones for
repainting ...) will pass and Your application will hang!!!
}


This is all U need, but keep in mind that there are a lot of other ways ...
another simple one can be through Windows Clipboard!:)

See U!
Stefano B.



FindWindow
"Christophe MINETTI" <cminetti@ulb.ac.be> ha scritto nel messaggio
news:41824B51.804A82A5@ulb.ac.be...
> Hi all,
>
> I have two different applications running and I would like them to
> exchange a character. I know this should be possible with Windows
> messages but I am not familiar with this stuff. If someone has a simple
> way to implement it, I would greatly appreciate.
>
> Thanks in advance
>
> Christophe
>
>
Technical Details
Message-ID: <41827ab9@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!proxad.net!213.200.89.82.MISMATCH!tiscali!newsfeed1.ip.tiscali.net!border2.nntp.ams.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!newsfeed.wirehub.nl!194.72.7.126.MISMATCH!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail
References: <41824B51.804A82A5@ulb.ac.be>

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>
Subject: Re: Communication between two applications
Date: Fri, 29 Oct 2004 19:15:36 +0200
Lines: 84
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.203.79
Message-ID: <41827ab9@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1099070137 212.141.203.79 (29 Oct 2004 10:15:37 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!proxad.net!213.200.89.82.MISMATCH!tiscali!newsfeed1.ip.tiscali.net!border2.nntp.ams.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!newsfeed.wirehub.nl!194.72.7.126.MISMATCH!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail