The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: raleeper on August 29, 2011, 08:51:12 AM

Title: Communication Between or Among Separate Running Programs
Post by: raleeper on August 29, 2011, 08:51:12 AM
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
Title: Re: Communication Between or Among Separate Running Programs
Post by: qWord on August 29, 2011, 11:55:51 AM
Interprocess Communication (IPC) (http://msdn.microsoft.com/en-us/library/aa365574(v=vs.85).aspx)
Title: Re: Communication Between or Among Separate Running Programs
Post by: 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.
Title: Re: Communication Between or Among Separate Running Programs
Post by: dedndave on August 29, 2011, 02:50:15 PM
i was a little surprised how well WM_COPYDATA works   :U
Title: Re: Communication Between or Among Separate Running Programs
Post by: ToutEnMasm on August 29, 2011, 07:07:48 PM

Two programs can communicate with atoms
RegisterWindowMessage
Title: Re: Communication Between or Among Separate Running Programs
Post by: raleeper on August 29, 2011, 10:17:47 PM
Quote from: qWord on August 29, 2011, 11:55:51 AM
Interprocess Communication (IPC) (http://msdn.microsoft.com/en-us/library/aa365574(v=vs.85).aspx)
That appears to hit the nail on the head.
Thank you.
Title: Re: Communication Between or Among Separate Running Programs
Post by: raleeper on August 29, 2011, 10:33:26 PM
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,
Title: Re: Communication Between or Among Separate Running Programs
Post by: raleeper on August 29, 2011, 10:36:09 PM
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.
Title: Re: Communication Between or Among Separate Running Programs
Post by: 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
Title: Re: Communication Between or Among Separate Running Programs
Post by: raleeper on August 30, 2011, 04:23:52 AM
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).
Title: Re: Communication Between or Among Separate Running Programs
Post by: dedndave on August 30, 2011, 05:01:46 AM
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
Title: Re: Communication Between or Among Separate Running Programs
Post by: dedndave on August 30, 2011, 05:14:23 AM
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
Title: Re: Communication Between or Among Separate Running Programs
Post by: raleeper on August 30, 2011, 09:03:17 PM
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


Title: Re: Communication Between or Among Separate Running Programs
Post by: 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.
Title: Re: Communication Between or Among Separate Running Programs
Post by: raleeper on August 31, 2011, 04:11:45 AM
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?
Title: Re: Communication Between or Among Separate Running Programs
Post by: dedndave on August 31, 2011, 04:56:22 AM
Quote from: raleeper on August 31, 2011, 04:11:45 AM
...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?

reminds me of a doctor story...

Patient: "Doc, it hurts when i bend my elbow like this"
Doctor: "Then, don't do that"

:P
Title: Re: Communication Between or Among Separate Running Programs
Post by: ToutEnMasm on August 31, 2011, 01:29:47 PM
To redskull,
Quote
Real Men(tm) use COM 

I have folowed the link and find
Quote
IDataObject Interface
Enables data transfer and notification of changes in data. Data
transfer methods specify the format of the transferred data along
with the medium through which the data is to be transferred.
Optionally, the data can be rendered for a specific target device.
In addition to methods for retrieving and storing data,
the IDataObject interface specifies methods for enumerating available
formats and managing connections to advisory sinks for handling change
notifications.

The term data object is used to mean any object that supports an
implementation of the IDataObject interface. Implementations vary,
depending on what the data object is required to do; in some data

The implementation of the IDataObject interface is  big work .
Perhaps as a real men can you just post it  :P

Title: Re: Communication Between or Among Separate Running Programs
Post by: redskull on August 31, 2011, 05:54:09 PM
Quote from: ToutEnMasm on August 31, 2011, 01:29:47 PM
Perhaps as a real men can you just post it  :P

In assembly?  I wish I were that manly... :'(

Title: Re: Communication Between or Among Separate Running Programs
Post by: PBrennick on September 01, 2011, 12:31:30 AM
Remember this. Don't use COM when there is no need to. (Of course if you like to beat yourself up ...)  ::)

Paul
Title: Re: Communication Between or Among Separate Running Programs
Post by: raleeper on September 01, 2011, 12:41:21 AM
Quote from: dedndave on August 31, 2011, 04:56:22 AM
reminds me of a doctor story...

Patient: "Doc, it hurts when i bend my elbow like this"
Doctor: "Then, don't do that"

:P

Yes.  My other favorite doctor story is:
Quote(Doctor examining patient)
Either you ain't got no pulse, or my watch has stopped)
{credit: Groucho Marx, Walt Kelly}

I can think of some cases where that might be apropos.