I have two window form applications written in C, one holds a struct consisting of two integers, another will receive it using the CreateFileMapping.
Although not directly related I want to have three events in place so each of the processes can “speak” to each other, one saying that the first program has something to pass to the second, one saying the first one has closed and another saying the second one has closed.
What would be the best way about doing this exactly? I’ve looked at the MSDN entry for the CreateFileMapping operation but I’m still not sure as to how it should be done.
I didn’t want to start implementing it without having some sort of clear idea as to what I need to do.
Thanks for your time.
A file mapping does not seem like the best way to handle this. It has a lot of overhead for simply sending two integers in one direction. For something like that, I’d consider something like a pipe. A pipe automates most of the other details, so (for example) attempting to read or write a pipe that’s been closed on the other end will fail and
GetLastError()will returnERROR_BROKEN_PIPE. To get the equivalent of the third event (saying there’s something waiting) you work with the pipe in overlapped mode. You can wait on the pipe handle itself (see caveats in the documentation) or use anOVERLAPPEDstructure, which includes a handle for an event.