Solved

Commenication between application

Posted on 1997-06-21
14
186 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 

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
 

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

806 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