Communication Between or Among Separate Running Programs

Started by raleeper, August 29, 2011, 08:51:12 AM

Previous topic - Next topic

raleeper

Two or more separate running programs can communicate in a limited manner by the SendMessage and GetMessage functions - provided they know each other's handle.
One way they can share handles is by a disk file.

My question is: "What are the best words or phrases to search for further information on this subject?"

Thanks, Robert


hutch--

Robert,

One of the useful ways is SendMessage with the HWND_BROADCAST handle and your own defined custom messages. That handles the contact between running processes, then you can use a memory mapped file opened between consenting apps to transfer data using the messages as the triggers.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

dedndave

i was a little surprised how well WM_COPYDATA works   :U

ToutEnMasm


Two programs can communicate with atoms
RegisterWindowMessage


raleeper

Quote from: ToutEnMasm on August 29, 2011, 07:07:48 PM

Two programs can communicate with atoms
RegisterWindowMessage


Yes, I see I'd better give a little more thought to defining the mssages,  I had assumed I could just pick a number.
Thanks,

raleeper

Quote from: hutch-- on August 29, 2011, 12:57:24 PM
Robert,

One of the useful ways is SendMessage with the HWND_BROADCAST handle and your own defined custom messages. That handles the contact between running processes, then you can use a memory mapped file opened between consenting apps to transfer data using the messages as the triggers.
Yes.  That makes sense,
Thanks.

redskull

Strange women, lying in ponds, distributing swords, is no basis for a system of government

raleeper

Quote from: redskull on August 29, 2011, 11:33:42 PM
Real Men(tm) use COM  :8)

http://msdn.microsoft.com/en-us/library/ms688421(v=VS.85).aspx
Thanks.
At this point I don't understand this at all, but I have filed the reference for later.  (I'm not asking for an explanation.  It will make sense when I know more [something] about OLE).

dedndave

COM looks great, but - a lot of documentation to pour through   :P
WM_COPYDATA is simple   :U

it depends a lot on what you want to do

dedndave

here's a quick little example

you open UserApp
it runs PmApp, sending the UserApp window handle on the command line
PmApp sends its' handle back to UserApp via WM_COPYDATA
once both windows have the handle of the other, you can send stuff back and forth with WM_COPYDATA

raleeper

Thanks to all who responded, with a wealth of information that I'm sure I'll be referring to frequently.

For now, I'm going to try a very simple method in which every participating program or instance puts its main window handle in a special file and sends a "new process active" message to the owner of any handle already there.  And so on.  I'll look at WM_COPYDATA - it may be better, but I don't see why I can't just use the clipboard.

The only messages I'll need are, roughly:
    Get Your Mail
    OK
    Error; Resend
    Failure
    Shut down

SendMessage with the HWND_BROADCAST handle may be useful, but I'm going to want the special file anyway, and it seems to me that broadcasting may interfere with other unrelated processes if I make errors during the development process.

Thank you all very much.

Best wishes, Robert



hutch--

Robert,

The HWND_BROADCAST message works fine, the trick is to register a custom message so that nothing else can interfere with it then any two or more running processes can communicate through that channel with safety.

This is what I use in QE to handle the multiple instance communiction.


    mov WM_INTSETTINGSCHANGE, rv(RegisterWindowMessage,"unique string here")
    mov WM_SHUTDOWN,          rv(RegisterWindowMessage,"another unique string here")
    mov WM_REFRESHMENUS,      rv(RegisterWindowMessage,"yet another unique string here")


Then you just send your registered windows message using the HWND_BROADCAST handle and any app that recognises the message can respond to it.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

raleeper

Quote from: hutch-- on August 31, 2011, 12:39:46 AM
Robert,

The HWND_BROADCAST message works fine, the trick is to register a custom message so that nothing else can interfere with it then any two or more running processes can communicate through that channel with safety.

This is what I use in QE to handle the multiple instance communiction.


    mov WM_INTSETTINGSCHANGE, rv(RegisterWindowMessage,"unique string here")
    mov WM_SHUTDOWN,          rv(RegisterWindowMessage,"another unique string here")
    mov WM_REFRESHMENUS,      rv(RegisterWindowMessage,"yet another unique string here")


Then you just send your registered windows message using the HWND_BROADCAST handle and any app that recognises the message can respond to it.

Well, to tell the truth I was thinking of doing it the lazy way - send to a known handle and just pick any number I want without worrying about whether it's unique or even assigning a string, except in my notes.  But that's not the right way, I know.  And I guess if I register the messages, I might as well broadcast.

OK, I'll forget about the lazy way,

Thanks, Robert

[later] I'm still leery of broadcasting.  Suppose my program crashes into a loop that does nothing but broadcast the same message repeatedly as fast as the os can process the SendMessages.  Mightn't that clog the other processes' message queues?