[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 199
  • Last Modified:

Commenication between application

Hi!

I want to commenicate between to programs. I want to have a program that answears "questions" from other programs. And I want a dll where a have the functions that phass a string or something to the program, and got a answear back. Hope somebody understand what I meen and helps. Thanks !

Chr
0
chrb
Asked:
chrb
  • 8
  • 6
1 Solution
 
icampbe1Commented:
There are quite a few ways to attack your problem.  If you want a 'quick' solution to get things going and refine it later then try this:

Get a message ID for your application(s).  Use this to comminicate between them:
   {Each program makes this same call to get the same ID}
   MessID := RegisterWindowMessage('My Special Message' );
   {Now, send to the required app (or brodcast)}
  PostMessage( App.handle, MessID, wp, lp );

  {the receiving app of course must receive the message and process it}

  A somewhat primitive way to send data around is to do so througha file.
 The file name(s) is agreed upon between the apps.

Like I said, this will get you 'on the air' while you impelement other methods.

Cheer,
Ian C.

0
 
chrbAuthor Commented:
Hi!

Could you please give me an example?

And would this handle a lot of messages between the program. My plan was to make a "server" for a virtual filesystem, where the client send a filename and got the real path back.

Chr
0
 
icampbe1Commented:
Do you want to communicate across platforms?  ie Are you using Win95, and are there some 16 bit apps that must participate?

0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
chrbAuthor Commented:
There would only be 32 bits, but they need to work at NT 4.0 too. I would make a DLL which other programs can use to communicate.
0
 
icampbe1Commented:
I was initially going to suggest using a broadcast type message  etc... but this is better.  
Use the WM_COPYDATA message facility.  It will permit you to send messages to and from all processes (including 16 bit participants).  The structure contains a pointer to the data you are trying to share  and that pointer gets corrected for you if you cross platforms.

When you send a WM_COPYDATA message, you specify the recipient, and the sender (as wParam) as well as the structure (as lParam).  The structure looks like:
TYPE
   PcopyData = ^TCopyData;
   TCopyData = Packed Record
      dwData: DWORD;
      cbData: DWORD;
      lpData: Pointer;
   END;

So in the code it looks like:

VAR  Buff: TCopyData;
....
SendMessage( Target, WM_COPYDATA, Handle, Longint(@buff) );

When the apps start up would be a good time for them to exchange handles.  You could use a RegisterWindowMessage to get a unique ID, to a broadcast, and go from there.

This is a very good solution for what you are doing.

Cheers,
Ian C.

0
 
chrbAuthor Commented:
Increase to 190
0
 
chrbAuthor Commented:
Increased to 200
0
 
chrbAuthor Commented:
May I have an full working example now? Where to programs finds the handles and communicate.

Thanks!

Chr
0
 
icampbe1Commented:
I am gone from the city (and my desk) till Friday Aug. 8th.  If you can wait till then, I will be happy to help you.  

Until then, the Application object has a handle property  you can use for communicating  - Application.Handle  <--- like this.

Cheers,
Ian C.
0
 
chrbAuthor Commented:
Could you give me an example now please ?

Thank you!
0
 
icampbe1Commented:
I am glad you commented, I received an E-mail of your comment and that reminded me to look here.  

The message facility that I described earlier is reasonably well documented in the Delphi docs.  However, there are many ways to do this.  It would help if I had an idea of your experience level.  

I will also suggest a very powerful communication facility you can use called 'memory mapped files'.  With this, all of the participating programs can communicate via a common memory space.  The nature and the length of the program messages is entirely up to you.  

If you have a little time, it would be well worth your time to read about windows messages and memory mapped files.

Also, are writing all of the programs that will communicate? If so, you can make better use of whatever facility you choose right from the start.  I'm sure you realize that it is somewhat difficult for me to write the entire communication faciltiy for you.  I am hoping to steer you in the right direction.  If you need addition help after looking at both messaging and mapped files, I'll gladly help you.

Ian C.
0
 
chrbAuthor Commented:
Where can I find info about memory mapped files ?

I have got some years experience with TP, and almost one with Delphi.
0
 
icampbe1Commented:
There is a very good book you can read which will show you about messages, mapped files, and much more.  

It is called the Delphi 2 Developer's Guide by Sams Publishing, ISBN: 0-672-30914-9.  I don't know if there is a Delphi 3 Guide yet but it doesn't matter.  All that you need is in this book.  It is $59.9 US and I believe that it is worth it.   It contains many examples of programs and difficult tasks that you encounter every day (much like your need).

I hope this is helping you.

Ian C.

0
 
chrbAuthor Commented:
I am sorry that I havn't graded you yet, I had one more question and I forgot it all. Sorry.

Chr
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 8
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now