Solved

Windows programming

Posted on 2002-06-04
6
199 Views
Last Modified: 2010-04-04
hi! i have 2 programs.  program A and program B.  i want program A to communicate with program B through windows messaging wherein program B will then do something on program A's command.  thanks in advance to everyone! :)
0
Comment
  • 3
  • 2
6 Comments
 
LVL 12

Accepted Solution

by:
Lee_Nover earned 100 total points
ID: 7053446
:)

if these programs will run on the same machine then you can use SendMessage
otherwise take a look into mailslots, pipes and sockets

for SendMessage you can simply do:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
    procedure SomeHandler(var Msg: TMessage); message WM_APP + 123;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.SomeHandler(var Msg: TMessage);
begin
     case Msg.WParam of
       0: Msg.Result:=0; // ofcourse you replace this by your handler
       1: Msg.Result:=1;
     end;

     Caption:=Format('%d -> %d', [Msg.WParam, Msg.Result]);
end;

procedure TForm1.Button1Click(Sender: TObject);
var hWin: HWND;
begin
     hWin:=FindWindow('TForm2', 'Form2');
     if hWin > 0 then
        SendMessage(hWin, WM_APP + 123, 1, 0);
end;

procedure TForm1.Button2Click(Sender: TObject);
var hWin: HWND;
begin
     // finc the receiver window - the other app
     hWin:=FindWindow('TForm2', 'Form2');
     if hWin > 0 then
        SendMessage(hWin, WM_APP + 123, 0, 1);
end;

end.


you can do the same for the other app .. just change the handler

that's the basics of messaging
0
 
LVL 45

Expert Comment

by:aikimark
ID: 7053743
don't forget Windows Atoms, too.
0
 
LVL 12

Expert Comment

by:Lee_Nover
ID: 7054552
then we could also go into Memory Mapped files and SendMessage with WM_COPYDATA :)
lots of ways to communicate in windows .. gotta love 'em :)
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 45

Expert Comment

by:aikimark
ID: 7055025
You can probably accomplish this through some CORBA or COM handshaking as well.  

Directory monitoring API. (indirect Sendmessage)
DDE (an oldie)
inter-process Winsock

Dang, this list could get long.

I don't want to confuse dabestprogrammerindauniverse, so let me recommend that Lee_Nover get the points for the correct answer.
0
 
LVL 12

Expert Comment

by:Lee_Nover
ID: 7055054
hey tnx ! :)
0
 
LVL 1

Expert Comment

by:bnemmers
ID: 7055454
I have a component at Torry's that does what you need
look for IPC. It's freeware but beware that this will not work in a NT service app.

http://www.torry.net/vcl/system/appscommunications/bmipc.zip

Good Luck Bill :-)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now