News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Interprocess Communication

Started by cman, May 29, 2015, 01:33:51 AM

Previous topic - Next topic

cman

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...

hutch--

If you are serious, memory mapped files AND Windows messaging are the action.

jj2007

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$.

Note the sender can be a console app, but the receiving end must have a window.

dedndave

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

dedndave

another method that would work...

you could enumerate windows, check the class name - when you find a match, you have the handle

dedndave

there are also mutexes and semaphores
not sure how that would go together, but you can add them to your thought basket

cman

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...