Discussion:
Noob Win32 IPC
(too old to reply)
noemailplease
2009-08-13 02:16:00 UTC
Permalink
Hi all,

Noob question about interprocess communications between two apps running
on the same machine.

I need to pass information from one application to the second (one-way).

Part of the problem is, the first app only has its data at infrequent
intervals and the second app only needs to read the IPC data at
infrequent intervals; but both apps cannot afford to sit around waiting
for the other. I am guessing I need some sort of asynchronous style of
comms, where the first app posts its message then continues working,
then at some later time the second app will read the message?

I was considering using files written on the HDD, but would prefer a
faster method. Maybe a mailslot is what I need? Maybe a named pipe?

Any advice? Sample codes are always welcome :)


TIA

P.S. The comms methods will be written into a win32 dll to be called
from both apps.
Scott McPhillips [MVP]
2009-08-13 03:41:38 UTC
Permalink
Post by noemailplease
Hi all,
Noob question about interprocess communications between two apps running
on the same machine.
I need to pass information from one application to the second (one-way).
Part of the problem is, the first app only has its data at infrequent
intervals and the second app only needs to read the IPC data at infrequent
intervals; but both apps cannot afford to sit around waiting for the
other. I am guessing I need some sort of asynchronous style of comms,
where the first app posts its message then continues working, then at some
later time the second app will read the message?
I was considering using files written on the HDD, but would prefer a
faster method. Maybe a mailslot is what I need? Maybe a named pipe?
Any advice? Sample codes are always welcome :)
The easiest way to do this is with SendMessage WM_COPYDATA. This assumes
that the receiver app has a window with a known wndclass name (so FindWindow
can find it) and that it pumps messages. SendMessage is a synchronous call,
blocking until the receiving app processes the message.

If that does not fit then you can consider a named pipe, or even a socket
connection on the loopback address.
--
Scott McPhillips [VC++ MVP]
noemailplease
2009-08-13 11:13:44 UTC
Permalink
Post by Scott McPhillips [MVP]
Post by noemailplease
Hi all,
Noob question about interprocess communications between two apps
running on the same machine.
I need to pass information from one application to the second (one-way).
Part of the problem is, the first app only has its data at infrequent
intervals and the second app only needs to read the IPC data at
infrequent intervals; but both apps cannot afford to sit around
waiting for the other. I am guessing I need some sort of asynchronous
style of comms, where the first app posts its message then continues
working, then at some later time the second app will read the message?
I was considering using files written on the HDD, but would prefer a
faster method. Maybe a mailslot is what I need? Maybe a named pipe?
Any advice? Sample codes are always welcome :)
The easiest way to do this is with SendMessage WM_COPYDATA. This
assumes that the receiver app has a window with a known wndclass name
(so FindWindow can find it) and that it pumps messages. SendMessage is
a synchronous call, blocking until the receiving app processes the
message.
If that does not fit then you can consider a named pipe, or even a
socket connection on the loopback address.
Thanks for the info.

The system cannot be blocking. Both applications must be able to
continue operations without having to wait for the other application.


ie.

app1: does stuff > writes to IPC process/file > continues doing stuff etc.
app2: does stuff > does some more stuff > reads from IPC process/file >
does something with the information > does some more stuff etc.



Any other ideas please?


This one really has me beat.
Ben Voigt [C++ MVP]
2009-08-14 00:07:34 UTC
Permalink
Post by noemailplease
Thanks for the info.
The system cannot be blocking. Both applications must be able to continue
operations without having to wait for the other application.
UDP (datagram) socket, ioctlsocket(FIO_NBIO), WSAAsyncSelect
Post by noemailplease
ie.
app1: does stuff > writes to IPC process/file > continues doing stuff etc.
app2: does stuff > does some more stuff > reads from IPC process/file >
does something with the information > does some more stuff etc.
Any other ideas please?
This one really has me beat.
Alex Blekhman
2009-08-13 12:59:26 UTC
Permalink
Post by noemailplease
I need to pass information from one application to the second
(one-way).
Part of the problem is, the first app only has its data at
infrequent intervals and the second app only needs to read the
IPC data at infrequent intervals; but both apps cannot afford to
sit around waiting for the other.
It seems that mailslots is what you need. Mailslots have all
advantages of asynchronous file-based communication while the data
is transferred via memory rather than actual files. You can find
an overview of interprocess communication mechanisms available on
Windows platform here:

"Interprocess Communications"
http://msdn.microsoft.com/en-us/library/aa365574(VS.85).aspx

Alex
noemailplease
2009-08-14 01:22:12 UTC
Permalink
Post by Alex Blekhman
Post by noemailplease
I need to pass information from one application to the second
(one-way).
Part of the problem is, the first app only has its data at
infrequent intervals and the second app only needs to read the
IPC data at infrequent intervals; but both apps cannot afford to
sit around waiting for the other.
It seems that mailslots is what you need. Mailslots have all
advantages of asynchronous file-based communication while the data
is transferred via memory rather than actual files. You can find
an overview of interprocess communication mechanisms available on
"Interprocess Communications"
http://msdn.microsoft.com/en-us/library/aa365574(VS.85).aspx
Alex
Thanks Alex, Ben and Scott

I have used a mailslot to solve the issue. Left it running overnight
and no issues.


Thanks again for your time and knowledge.


Merci.

Loading...