PDA

View Full Version : PostMessage() across process boundaries equivalent



TheKedge
26th January 2006, 13:29
Hello,
is there anything equivalent to the windows PostMessage() across application boundaries?

HWND hWnd = ::FindWindow(NULL, "MyOtherApplication");
::PostMessage(hWnd, IntegerMessageID,
(WPARAM)param1,
(LPARAM)param2);

I've got Qt GUI apps talking to a COM server that sits on a big heap of code. Parts of that code should be able to tell the GUI that it needs updating. Before I started using Qt I was using the PostMessage(). My GUI could catch it and ask the COM server for fresh info.

any (simple) ideas?

thanks
K

wysota
26th January 2006, 13:32
Can't you use COM techniques (activeX) for that?

TheKedge
26th January 2006, 14:21
Yes, you can.
but, two things: (both my fault)
The code I have is organised into into layers. my machine layer is close to the hardware. An automation layer looks after the interaction between machines. My COM server provides a wrapper interface to the automation layer. My GUIs are on top and should 'look like' the machines. I don't really want my 'machines' to know about anything else above them - except that the machines can change status on their own and should let the GUIs know that they need updating. The GUI can then go and ask the COM server for new info.

I'm sure there are several ways of doing this: I could poll from the GUI with a 'stateChanged()' func (easy but ugly), or pass function pointers that the machine objects can call to order updates (ugly and ugly). I just thought that PostMessage() is fairly easy and light-weight. If there were a Qt equivalent in QProcess or something...

Further, my COM is uni-directional: I don't (or didn't) want to bang in another interface(s) so that the server can call all the programs that access it (there's no real need).

and, secondly:
eventually I'd like to remove the MS dependencies. and eventually would like to get away from COM altogether, I'll need to run on other operating systems. I think that'll be a challenge - I'll need to start learning CORBA ' stuff.

so ... am I doing things the wrong way? grateful for any ideas.

Thanks
K

Chicken Blood Machine
26th January 2006, 18:15
Do you have a commercial license? If not don't bother reading the rest of my answer.

With the QtSingleApplication solution code, you can set up your different apps to be singletons (I'm not sure if this is appropriate for you). Then, to send a message, you can just execute the app using QProcess and a commandline that describes your new message. If the app is already running, then a message is just sent directly to the running app.

In fact, if you inspect the QtSingleApplication code carefully, you can probably change this to eliminate the singleton behaviour, but maintain the message passing behaviour.

TheKedge
26th January 2006, 22:36
Wow, nice hack:cool: . That sounds like it's worth playing with! I'll give it a try.

thanks
K

wysota
26th January 2006, 23:39
Or you can just use winapi to make your call and then catch it with platform events (winEvent or something like that -- never used it, so check the docs).

Chicken Blood Machine
27th January 2006, 00:06
Doesn't work very well on other platforms though.

wysota
27th January 2006, 00:20
Just like COM itself.

Chicken Blood Machine
27th January 2006, 00:27
Just like COM itself.

...which is why he said this:



eventually I'd like to remove the MS dependencies. and eventually would like to get away from COM altogether, I'll need to run on other operating systems. I think that'll be a challenge - I'll need to start learning CORBA ' stuff.

wysota
27th January 2006, 01:02
Yes, I missed that.

Anyway, things like shared memory or named pipes are always an alternative (yes, I know Qt doesn't have direct support for them).

BTW. Corba (and other RPCs) involve using network sockets, so with simple apps it might be simpler to just use network sockets yourself instead of higher level protocols.