I have 2 programs, and I need a way for one of them to somehow send a message to the other. I've looked into the SendMessage function in the Win32 API, and while it works great as long as you have a window handle, my program needs to be able to run while logged off under a service, which means it cannot create a window handle.
Is there any way I can receive messages from another process without having a window handle created? I've been looking to see if Win32 has some other way that I can hook into the messaging so that I don't depend on having a window handle, but there has to be some way to communicate between processes at a basic level, doesn't there?
I have looked into using Pipe's to do this, but have run into huge permissions issues with that on top of that being much higher level than I'm really looking for. All I need to be able to do is send a simple custom int message so my process knows it's time to shut down.
If it's really as simple as signalling the other program to shut down, then you can create a named event. Both processes create the event with the same name. One watches it and the other can signal it. The one watching can do that with a modified message pump that uses MsgWaitForMultipleObjects instead of PeekMessage.
There's a slight denial-of-service risk here, as a malicious process could create an event with the same name and cause your other application to exit.
If you need more sophisticated communication, you'll need a pipe, mailslot, shared memory, file watches, registry watches, or use another synchronizable kernel event (Mutex, Semaphore, etc.).