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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using Global Variable for Inter Program Communication

Status
Not open for further replies.

Panthaur

IS-IT--Management
Jul 26, 2002
78
US
I am looking to create an easy, simple inter-communiction system between 2 applications.

I have a c++ console app (technically not a dos app because it does require use of a dll) that I am writing a menu application for, and I want to be able to send messages back and forth between the 2 programs. I was thinking of trying to make use of global variables to achieve this communication, or possible a text file on the users hard drive.

Does anyone have any suggestions on:
a) Will this approach work?
b) How to achieve this communication in another way?

Thanks for the input!

Panthaur
 
I definitely wouldn't use the registry for constant writing of data (i.e. talking back and forth between apps). The registry is designed for storage and retrieval of app config data, not constant reads/writes---although it's possible to do so. What I would do is investigate the SendMessage API. Look for samples on the net. One of my favorite sites for VB samples is A SendMessage sample is too lengthy to post here, but there are plenty out there if you use a search engine and look up "VB SendMessage". That's what SendMessage is for, talking back and for between apps. I just recently tied two VB apps together using SendMessage. Works great and it's fast.
 
Microsoft knowledge base article 176058 explains how to pass string data between two applications.


I also discussed a similar solution in my previous post but the problem is Panthaur cannot use SendMessage between two application as atleast one of the application is a console application.
 
Hence my suggestion concerning the use of named pipes or mailslots...
 
I'm actually going to try and implement sendmessage this weekend. I figure that if I am using API's to send data to the registry from my console app, I should be able to use the API calls for sendmessage, and I don't have to worry about corrupting an already "shaky" registry.

Panthaur
 
The problem is that SendMessage requires the hWnd of a target window that has a windows message handling queue. What Hypetia was getting at is that console applications (normally) don't have that...
 
Well, I guess I am stuck with the registry method then... I don't have much of a choice.

Thanks for all the help and suggestions,
Panthaur
 
So create an invisible window for the console app that'll handle the message queue, or use a named pipe or a mailslot. Or even a shared COM object...
 
I wouldn't know how to create an invisible window in C to handle the messages. I am most a VB programmer, and I was lucky to get the registry method working in C++. I know the basics of C++, but when I have to get into using the windows API's, I just don't know enough yet, an I have to get this project done, so I don't have the time to go thru a c++ learning curve.

All in all, the registry method is working GREAT. I have done a lot of testing, including writing 2 apps to communicate back and forth for 14 days testing my registry writing and reading method, no crashes or slowdown in the test computer. I increased the writing and reading to 5ms instead of the 50ms that I have programmed into the actual app, and have still had stellar results.

Take care,
Panthaur
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top