Archived

This topic is now archived and is closed to further replies.

Guy Hoodinrob

How do you exchange the values of variables between Windows programs?

Recommended Posts

Guy Hoodinrob    122
Hi, I have a Windows MFC Dialog based application that does some image processing on a video input source and also displays some data about the image. This data consists of just 4 or 5 numeric values. What I want is to be able to read these values from within other completely seperate windows applications. What is the best way to do this? All i''ve thought of so far is readProcessMemory() (MFC command) but that does not provide a consistant interface to the data, or writing out the data to a file, but thats too slow and basically rubbish. Any help greatly appreciated.

Share this post


Link to post
Share on other sites
GaulerTheGoat    122
First, I don''t know any MFC. If I understand, the processes (applications) will know that they are sharing data with your app - ie. your app cannot (as far as I know) share data with any other process without that processes consent (although, with Windows...)
Anyway, I believe the simplest way to do this is by FileMapping. It doesn''t actually involve using a file (although you must know that whether you like it or not, pieces of your apps memory are constantly being swapped in and out of the paging file while it is running). Your main app can create a FileMapping object and name it. Then other processes can open a FileMapping object and request the same name. Windows will then share the same FileMapping object between these processes.
The FileMapping object itself is basically just a block of memory like an array that is global to all of Windows itself. Look up, say, CreateFileMapping on MSDN to see the details.
Does this help?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
Thanks everyone, I''ll look into both of those methods

/Guy Hoodinrob

Share this post


Link to post
Share on other sites
Master Mofo    122
you can make a DLL that will return the data you want if you call a certain function from it. The Dll could be used by both programs. or you can even put your whole application in the DLL and make the 2nd application call it.

There is also another way where you can read data stored in memory for a Window by using GetWindowLong(). but first you need to store the variable in the Window''s memory by SetWindowLong() in the first program. BUT this can only happen if the 2nd Program is a Child or a Parent Window to the 1st program. These methods are called Subclassing.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
Hi Master Mofo,

Yes I thought about that, and having the Dialog application available as a DLL is a good interface, but how can I put a whole existing MFC Dialog application into a DLL? Also I havent seen many DLLs that open windows but I assume thats possible.

/Guy Hoodinrob

Share this post


Link to post
Share on other sites
Mastaba    761
You can also use DDE to exchange data between applications. Fairly simple to implement too (basic DDE that is). Although for just a few numbers, a shared filemap is the way to go.

[edited by - Mastaba on September 2, 2003 6:34:10 PM]

Share this post


Link to post
Share on other sites