|
-
December 8th, 2004, 09:47 AM
#1
Sharing Data between two executables
Hi Gurus,
I have a problem to share a data between two executables. The shared memory shall act as the Queue. The Exe1 puts a data and Exec2 reads from it and viceversa.
The problem is the type of data shared between them is of differenet type. Both the execuatables are shareing data using three different structures. Even the shared memory shall grow or shrink as per the number of data objects.
Could you please suggest me what data structure shall I use to meet above all requirement.?
If anyone of you have similar code, Please post it here.
Regards,
Nagesh
-
December 8th, 2004, 11:30 AM
#2
Re: Sharing Data between two executables
One solution is socket. Also check out WM_COPYDATA.
Kuphryn
-
December 8th, 2004, 11:44 AM
#3
Re: Sharing Data between two executables
How many ways of communicating between processes... let me count the ways.
1, 1000
2, 2000
*laugh*.
Firstly, if you're dealing with structures you need to be able to turn the structures into a buffer/stream and back again. You can use CMemoryFile with CArchive to do this (or if you're writing to files CFile and CArchive).
Now there are a variety of ways that you can get two applications to communicate with one another.
(1) Sockets & client/server. In this case one application can communicate with another application even if they're not on the same machine. Either that or both applications can connect to a server and poll it ever so often to find out if new data is available to be picked up. Latter is probably better : peer to peer (i.e. application to application) is a pain unless you're doing something REALLY simple.
(2) Named pipes. A little tricky if you're not used to overlapped behaviour but nice just the same. Plenty of examples in MSDN.
(3) Writing out to files. Yes ! You can do this ! Each process could poll (i.e. look at) a file on the hard drive and check its modified date. If this changes then the process knows that it has new data and therefore opens the file, gets the data and hey presto ! This is the least nice in programming terms but also the easiest.
(4) Shared dll. I believe a dll can have shared memory between processes using segments, but never used this before so I don't really know.
(5) COM as a local server. This is what Word, Excel use to allow outside applications to communicate with them.
(6) If you're in .NET you have message queues but I don't know if you've got this facility in ordinary C++ and can't be bothered looking it up in MSDN.
(7) Clipboard and message passing. You can (after you've got a stream of bytes of data) copy them to the clipboard. Then by various methods find the main window of the application you want to send the data to and post a known message to it to retrieve the data.
(8) .... probably more but I've ran out of steam.
The above should give you something to go on. What you choose really depends on how you want your application to behave. And what OSes it needs to run on (a few of the above only work on W2K and above).
And check out the FAQs. I'd put good money on there being something in the C++ FAQ about this... or the threading FAQ possibly.
Darwen.
Last edited by darwen; December 8th, 2004 at 11:51 AM.
-
December 8th, 2004, 01:24 PM
#4
Re: Sharing Data between two executables
Check out Dynamic Data Exchange (DDE) in MSDN. It's a forerunner of OLE, and, while a little clunky, is pretty easy to implement.
Regards
Robert Thompson
-
December 8th, 2004, 06:00 PM
#5
Re: Sharing Data between two executables
-
December 10th, 2004, 03:16 AM
#6
Re: Sharing Data between two executables
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|