artyom.stv
artyom.stv

Reputation: 2164

Cross-process interaction under C++

Please help, how can I organize the process-process data exchange (in Windows, if that matters)?

I have process1.exe which calls process2.exe with a few command line arguments. I want to track "progress" of process2 from process1 (say, some int value). It (that int value) can be accessed from process1 permanently or each X ms - doesn't matter.

Will be useful any solution: WinApi or Qt.

Thank you everybody! All answers are very useful! :) Many thanks!!

Upvotes: 3

Views: 1963

Answers (5)

Steve
Steve

Reputation: 1810

An obvious omission in the options presented so far is COM. I'm expecting the usual flurry of "COM is crap" responses, but in my experience this hasn't been the case.

Upvotes: 1

Erik
Erik

Reputation: 91320

OTOH:

  • stdin/stdout redirection
  • Named pipe (CreateNamedPipe)
  • Anonymous pipe (CreatePipe)
  • Sockets (socket, connect, bind)
  • Shared memory (CreateFileMapping, MapViewOfFile)
  • Windows messages (e.g. WM_APP)

Pick one - Windows messages or shared memory may be the easier ones.

Upvotes: 5

Thomas Matthews
Thomas Matthews

Reputation: 57749

There are several methods:

  • Sockets
  • Messages
  • Shared Memory (files)

The issue is that Process2 will be broadcasting and Process1 will be listening. Process1 will need to know when Process2 is finished and maybe the percentage complete.

I believe Sockets would be the better route, but that depends on the application, development schedule and familiarity of concepts.

Upvotes: 3

Jon
Jon

Reputation: 437774

There are many options here:

  1. You can redirect the standard output of process2 and have it output updates however often you like
  2. If stdout is being used for something else, you can use a named pipe between the processes
  3. You can also use named shared memory, which will require less overhead and probably be easier to implement (the downside is that you may need to also do cross-process synchronization)
  4. If process1 is running a message pump, then you can also use normal Windows messages (look at WM_COPYDATA)

Upvotes: 4

stefan
stefan

Reputation: 2886

You can simply send messages with Windows Api (SendMessage).

Upvotes: 1

Related Questions