Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How 2 connect 2 programs? 3

Status
Not open for further replies.

Totte

Programmer
Jun 6, 2001
317
SE
I has made a program with a usefull function and i have an idea about another program which includes hardware and thus is in the future. The two programs should be able to run individually and perform their task but if BOTH are running they should syncronize their datas (project names and such) to my likeing. The 2 programs will be totally independant and therefor i see no way of making them in the same package. As i use CreateMutex to avoid multiple instances from running i understand that i can use something like that to exchange datas between the programs but is there a better methode than Mutex???
I will have to read on it but i'm currently just looking for a good method of exchanging datas between programs.

Totte
 
You could use named pipes or anonymous pipes. See for am example on anonymous pipes.

James P. Cottingham

When a man sits with a pretty girl for an hour, it seems like a minute. But let him sit on a hot stove for a minute and it's longer than any hour. That's relativity.
[tab][tab]Albert Einstein explaining his Theory of Relativity to a group of journalists.
 
I just checked notes. Besides pipes you can use WM_COPYDATA, the clipboard, DLL's, shared memory, mailslots, dynamic data exchange (DDE), NetBios, sockets, remote procedure calls (RPC), ActiveX, and Microsoft Message Queue (MSMQ). These are called IPC (interprocess communications).

James P. Cottingham

When a man sits with a pretty girl for an hour, it seems like a minute. But let him sit on a hot stove for a minute and it's longer than any hour. That's relativity.
[tab][tab]Albert Einstein explaining his Theory of Relativity to a group of journalists.
 
Gee...thanks man. I've seem to have a lot of reading to do....but the i will learn even more :)

Totte
 
I once made a chat program that did not use
sockets or anything like that. The machines
did have to have netbeui installed so I could map
a shared folder on one mahine. The programs just
periodically scanned a file in this folder and got
the proper information from it. there are issues with
timing that you will have to work out but it should
be simple with only two programs scanning the same
resource.

tomcruz.net
 
OK butthead but i'm having an idea of a system that is two programs, each doing their job, the one with the hardware in the PC (time information) and another system utilizing an external hardware. Either program/system can run on it's own but together they could syncronize names and information which otherwise had to be done manually.
And....the real reason.....deep down: I WILL LEARN TO MAKE THEM COMMUNICATE just for the fun of it....or the kick or whatever....

Totte
 
Are your both programs running on same machine? If so, the easiest way to make them communicate is to register new windows messages (WM_USER + something) for every special information/task and send them between applications when you need info-exchanging, synch. or whatever. This is very easy and straightforward way of doing things. But, beware that this is not very fast method, so if you need something time-critical it is better to stick to more hard-core solutions.
 
I'm doing just that. I'll give it a go tomorrow, thanks.

Totte
 
I think that I would prefer sockets as that is what I presently have experience in. Bnasty stated that windows messages is not a very fast method. I would like to know if sockets is potentialy faster or slower.

tomcruz.net
 
As i'm not into sockets or indeed any other inter-processing communication, i'd like to know:
"WM_USER + XXX": local or LAN-wide??? (my guess: local)
Sockets: local or LAN-wide??? (my guess: LAN-wide)

As i understand it a LAN wide communication works just fine as local too thus giving me (or the user) the choise of using different PC's for each part OR running both on the same mashine.

Timing is not an issue here in this project, a slack of 3-5 seconds i acceptable, the programs has to exchange a few datablocks "within a working day".

Totte
 
sockets - local and lanwide and world wide.

The sockets implementation is very straightforward.
use the example chat program from builder to get
aquainted.

tomcruz.net
 
Sockets? Yes - it is straightforward and easy method (well, at least in Builder :) in which it doesn't matter on which machine you run your programs (as long as you know IP addreesses :) You can implement it with 'old' Borland's socket components, or use new Indy components, depends on the way you want your software to work (with blocking or non-blocking connections...)
Anyway, windows messages ARE simpler method if you are running on the same machine and don't care about speed that much...
 
Use IPC to manage App instances:

If you want your Application run only one instance you need to implement an IPC method. Why?
For example your App runs, and the user drop a file (maybe a datafile that can be used in your App) to App desktop icon, instead of run an other instance which opens the datafile load it to running App.

Three important things you need to do this:
1. A Mutex
2. A registered windows message which is unique entire for system (Simpliest way to identify you app main window. Do not use Window Title, it may be change or it is not unique for entire system)
3. An IPC method to pass command line string from new instance to other (I prefer WM_COPYDATA. I'ts easy to implement.)

If you want I'll put the working & tested code to this thread. Reply!

(Sorry about my english. I'm not a genius.)

Unbornchikken
 
I have already used Mutex to avoid multiple instances from running and there will be no need for drag and drop.

The description is really quite simple:
One program tracks and stores the use of one type of human resource and controls what project and such.

The other program tracks hardware supply and the inter-communication is simply the projectnames and resources used to make a common report.

Thus i do not need to put it together manually.

Totte
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top