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!

Exchange Data between Application

Status
Not open for further replies.

Simse

Programmer
Feb 24, 2005
22
Hi all,

I've got a problem with exchanging data between
applications. I have an application that is running
24hours, and another application, that does some
kind of statistic. Sometimes I need actual data from
the 24hour application, but how do it get these data?

I already tries things like MailSlots, but got there
big problems with the timing.

Perhaps somebody has got an idea.

Cheers
Simon
 
Why not simply collect these data to a file?
Or may be TCP/IP sockets - write your resident program as a server, answering to external requests?
May be pipes?
 
Hi,

thanx for suggestions. I dont want to use
seperate files, because of sharing probs etc.
or some crash.
But I found another way, by using CWnd::SendMessage
where I can search the second appication with function
FindWindow (by name), and then write an WM_ to get
the Information. Only problem here is, that u only
have WPARAM and LPARAM datatypes to send ur information.
But I heard theres a possibility to send a struct by
typecasting the WPARAM and LPARAM.

Cheers

 
You could use shared data segments.

You could also use memory mapped files and placement new and a a named memory space
see CreateFileMapping(...)
and MapViewOfFile(...)

and assign your objects into that space

Jeb
 
But I heard theres a possibility to send a struct by
typecasting the WPARAM and LPARAM.

You can send adresses of your data structures, but the data will be accessible only for that application own threads. Don't know anything about memory sharing between applications, may be follow Jeb's advice?

I dont want to use seperate files, because of sharing probs

To avoid collisions using common data files you can use Windows messages for synchronization between both applications.
 
Windows messaging with WPARAM and LPARAM require that there actually be a window, and is a push type communication metaphor rather than a data sharing metaphor.


for data segment sharing from a dll, add this to your .def file
Code:
SECTIONS
    ; This is our homebrew shared datasegment
    .CommonClientData    READ WRITE SHARED
set up the shared variables in the cpp
Code:
// Set up shared data segment, 
// be sure to INITIALIZE THE VARIABLES
#pragma data_seg(".CommonClientData")
    [COLOR=green]// exported variables (visible to client)
    // use InitInstance and Exitinstance to track user count
    // (singleton pattern)[/color]
   __declspec(dllexport) int giUserCount = 0;

    [COLOR=green]// some data to exp[eriment with[/color]
   __declspec(dllexport) int iSharedInt[5]= {0,0,0,0,0};
     
   [COLOR=green]// data to be allocated via CreateFileMapping and MapViewOfFile
   // UnmapViewOfFile when last client disconnects[/color]
   __declspec(dllexport) CSNTData *pSNTData = NULL; 
   
#pragma data_seg()

Note: clients using this data will have to "__declspec(dllimport)" it

Jeb
\0
 
> Windows messaging with WPARAM and LPARAM require that there
> actually be a window

No, you could send messages to a windowless thread - PostThreadMessage()
 
mingis,
I stand corrected. Can the called program access the memory area pointed to by the message params. Is there a sysallocate or something that allocates 'safe' memory?

Jeb
\0
 
> Is there a sysallocate or something that allocates 'safe' memory?

Don't know.
 
Hi all,

it is possible to send data with windows-message SendData between 2 diffrent applications.
The best way is to use the WM_COPYDATA to receive
the send data.
Very usefull page for that is:

Cheers Simon
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top