The MASM Forum

General => The Campus => Topic started by: cman on May 29, 2015, 01:33:51 AM

Title: Interprocess Communication
Post by: cman on May 29, 2015, 01:33:51 AM
I read Windows program can send another program data or signal an event by sending a " WM_COPYDATA" message . But how should an unrelated program get the handle of the program that it wants to send the message or signal to? I guess one program could store its handle in a location that others could read , like a file. Whats the best way to do this? Thanks for any information...
Title: Re: Interprocess Communication
Post by: hutch-- on May 29, 2015, 01:57:31 AM
If you are serious, memory mapped files AND Windows messaging are the action.
Title: Re: Interprocess Communication
Post by: jj2007 on May 29, 2015, 02:26:43 AM
WM_COPYDATA works fine. In case you have MasmBasic installed, go to File/New Masm source in RichMasm, and click on Client or Server somewhere in the middle of the template window. See also SendData and CopyData$ (http://www.webalice.it/jj2006/MasmBasicQuickReference.htm#Mb1081).

Note the sender can be a console app, but the receiving end must have a window.
Title: Re: Interprocess Communication
Post by: dedndave on May 29, 2015, 05:18:24 AM
i've ran into this problem, too   :biggrin:

one program i wrote passes the handle on the command line in hex
it is designed to run 2 instances
the first instance is the "master" and the second instance (same program) is the "slave"
if there is no hex parameter on the command line, the program runs as master
if there is an 8-digit hex value on the command line, the program runs as slave (and knows the master handle)

but, there are probably other ways to do this
one way....

register a message using RegisterWindowMessage
these messages have named strings
if you register a name that has already been assigned, you get the same message number   :P
then, query and listen for that message number
pass the window handle in lParam
something like that should work
Title: Re: Interprocess Communication
Post by: dedndave on May 29, 2015, 05:27:09 AM
another method that would work...

you could enumerate windows, check the class name - when you find a match, you have the handle
Title: Re: Interprocess Communication
Post by: dedndave on May 29, 2015, 05:36:38 AM
there are also mutexes and semaphores
not sure how that would go together, but you can add them to your thought basket
Title: Re: Interprocess Communication
Post by: cman on May 30, 2015, 02:32:27 AM
Thanks for the information! I haven't written any code that uses communication between processes to this point , so I thought I might give it a try...