Solved

Commenication between application

Posted on 1997-06-21
14
183 Views
Last Modified: 2010-04-04
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
Comment
Question by:chrb
  • 8
  • 6
14 Comments
 
LVL 2

Accepted Solution

by:
icampbe1 earned 200 total points
ID: 1337379
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
 

Author Comment

by:chrb
ID: 1337380
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
 
LVL 2

Expert Comment

by:icampbe1
ID: 1337381
Do you want to communicate across platforms?  ie Are you using Win95, and are there some 16 bit apps that must participate?

0
 

Author Comment

by:chrb
ID: 1337382
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
 
LVL 2

Expert Comment

by:icampbe1
ID: 1337383
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
 

Author Comment

by:chrb
ID: 1337384
Increase to 190
0
 

Author Comment

by:chrb
ID: 1337385
Increased to 200
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:chrb
ID: 1337386
May I have an full working example now? Where to programs finds the handles and communicate.

Thanks!

Chr
0
 
LVL 2

Expert Comment

by:icampbe1
ID: 1337387
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
 

Author Comment

by:chrb
ID: 1337388
Could you give me an example now please ?

Thank you!
0
 
LVL 2

Expert Comment

by:icampbe1
ID: 1337389
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
 

Author Comment

by:chrb
ID: 1337390
Where can I find info about memory mapped files ?

I have got some years experience with TP, and almost one with Delphi.
0
 
LVL 2

Expert Comment

by:icampbe1
ID: 1337391
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
 

Author Comment

by:chrb
ID: 1337392
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Delphi OLE Error 8 84
Newbie Thread Programming 1 118
delphi exception 7 58
Delphi inherited method 6 42
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

747 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

18 Experts available now in Live!

Get 1:1 Help Now