?
Solved

Windows programming

Posted on 2002-06-04
6
Medium Priority
?
204 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 12

Accepted Solution

by:
Lee_Nover earned 300 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 46

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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 46

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

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…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month14 days, 14 hours left to enroll

771 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