#### Archived

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

# exchanging data between applications

This topic is 5806 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

hey guys, i want to exchange data between two applications. lets say one app asks the user for a string and i want the second app to print the string on the screen. actually, it''s more complicated. first i tried giving the address of an array to one app (with commandline switches), but that didn''t work properly. i don''t want to write the data to a file, so have you any suggestions how to exchange datas between two (or more) apps? anyway, i could do it another way in this case. well, i''ll explain my situation: i have an application unsing directx. now i want, that the user may select the rendering device. yeah, a dialog box would be fine. but the thing is, i need to include windows.h, and mfc doesn''t like that, so i can''t compile my program. now i have written a little app doing the selection-work, but how to i pass that information to my main application? any solutions would be helpfull... greetz

##### Share on other sites
well, i finally found a way...

for anyone who''s interested in, see this msdn-article:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ipc/datacopy_1lvd.asp

##### Share on other sites
Easiest, but definitely not safest way :

Create a DLL exporting your variable
Define your variable in a named section
// CPP file#pragma data_seg("MYSECTION")char buffer[1024];#pragma data_seg()

Link the DLL in both programs.

Now both programs can read/write to that variable.
You''ll probably need to add locks (like for threads) to prevent simultaneous access.

##### Share on other sites
If its something like selecting a rendering device in win32, you may just want to save that data to the registry and read it out in the next program.

funcs:
RegOpenKeyEx()
RegCreateKeyEx()
RegQueryValueEx()
RegSetValueEx()
RegCloseKeyEx()

Alternatively you could use some sort of inter process communication like pipes, or just invoke the 2nd app from the 1st via CreateProcess() and pass in string through command line arguments.

##### Share on other sites
anybody know how to do the data_seg() with any compilers other than msvc? i used to use it for setting global hooks, but i havent found any other way to do it

Edited by - barazor on February 23, 2002 9:59:28 PM

##### Share on other sites
quote:
Original post by barazor
anybody know how to do the data_seg() with any compilers other than msvc? i used to use it for setting global hooks, but i havent found any other way to do it

What compiler are you using ?
gcc : asm(".section whatever");

check the doc for your assembler and try to spit out the commands yourself...

##### Share on other sites
ahh yes, forgot to say, im on mingw32(gcc)

##### Share on other sites
quote:
Original post by barazor
anybody know how to do the data_seg() with any compilers other than msvc? i used to use it for setting global hooks, but i havent found any other way to do it

Edited by - barazor on February 23, 2002 9:59:28 PM

You can use a memory mapped file - the hook example at winprog.org does it this way (look for it on the faq page).

Another approach to exchanging data between apps is DDE. However, it's not the easiest approach.

Edited by - lessbread on February 24, 2002 2:32:34 AM

##### Share on other sites
There''s an article on MSDN called "Inter-Process Communications". It''s in your win32 reference section. That''s what you''re talking about, and there are several options.

##### Share on other sites
quote:
Original post by McEck
i need to include windows.h, and mfc doesn''t like that, so i can''t compile my program.

now i have written a little app doing the selection-work

If I understood you correctly: Are you using a separate exe to put up a dialog box because you couldn''t include windows.h?

If that''s the case, just don''t include it and you''ll be fine. MFC includes windows.h internally. Or am I missing something here?

##### Share on other sites
quote:
Original post by IndirectX
If I understood you correctly: Are you using a separate exe to put up a dialog box because you couldn''t include windows.h?

If that''s the case, just don''t include it and you''ll be fine. MFC includes windows.h internally. Or am I missing something here?

i''m using a seperate exe, but because i have to include windows.h. other parts of my program need stuff of it. i tried including some other files, but then i get linker errors and that stuff...
that''s why i''m using a second program.

by the way, i''m using a pipe for data exchange now, works fine.

greetz