|
Post by dragonjim on Mar 7, 2012 17:16:10 GMT 1
I am trying to send a numerical value from one program to another, so that the latter program can then perform a specific action.
To this end, I have scoured the Windows API library, but nothing seems to describe exactly what I wish to do.
I use the FindWindow function to get the receiving applications handle (should I be going for a Process ID?). With the returned value, SendMessage quite happily closes the window when the WM_CLOSE constant is sent. Is there any other way of using SendMessage to pass the required number?
I have tried the DispatchMessage(Msg), GetMessage(Msg,etc) combination; this does receive a message (Msg) but not the one I sent! Also, there doesn't seem to be way of directing the message with DispatchMessage().
Just for information, the message format I am using is:
Type POINTAPI x As Long y As Long End Type Type Msg hWnd As Long Mess As Long wParam As Long lParam As Long time As Long pt As POINTAPI End Type
Both PostMessage and SendMessage have no methods for passing the Msg type, unlike DispatchMessage, and neither does BroadcastSystemMessage, which seems pretty indiscriminate.
I would appreciate any help any one can give me, even if it's telling me I've totally misunderstood the message functions!
|
|
|
Post by 649psoft2 on Mar 10, 2012 9:34:10 GMT 1
Dragonjim you are wading a little deep into the mire here.
In general messages are private to each application or running program.
There are a couple of o/s inter-process exceptions to this rule.
I suggest you refer to the Win 32 SDK Online Help from Microsoft.
As I understand it BroadcastSystemMessage send a message to all running processes or applications in the mutitasking evironment. For example you could send a message to minimize all open windows of all running processes in the desktop.
The API provide CreatePipe and CreateNamedPipe for inter-process messaging. Create Pipe works a bit like dropping a file. CreateNamedPipe is where a sending application (described as server process) sends messaging to one or more receiving applications (described in the abstract ms-lingo as a client process). It is a bit more complex.
|
|
|
Post by dragonjim on Mar 10, 2012 15:01:42 GMT 1
Thank you once again for your speedy reply and advice.
I understand that inter-process communication is limited for security reasons (or so it says on a lot of the Microsoft Help pages) but it seems that such functionality would be very useful in this modern world of multi-process applications.
However, your comments about the mire are very apt and, before I disappeared comletely, I reverted to the time-tested I/O file type of communication where the receiving program has a Timer object which constantly searches for a file to be created and, if it finds it, completes the required task.
My problem with this type of communication is that it is prone to errors and very restrictive - the sending and receiving applications must be in fixed positions OR their paths must be written to pre-defined registry values otherwise the operations fails. It seemed a simpler task, to me, if I was able to communicate directly with the receiving application through its Process or Window handle.
I shall take your comments on board, especially regarding the CreatePipe API, and keep chipping away at this problem - if I find a solution, I'll post it on this thread.
|
|
|
Post by 649psoft2 on Mar 11, 2012 9:02:45 GMT 1
If you are an experienced API programmer the CreateNamedPipe can be implemented with a little time I haven't used it but yes it would be good to use.
From the security perspective it makes some sense as an applicaiton would have to be specificly programmed capable of receiving these messages. If this were not the case then you could control applications not intended to be controlled in that way when they were written and this would cause a lot of problems in the internet so many people now use.
At any rate there are plenty of above board ways to automate other processes even if they are slower workarounds they do not have the possiblity to cause the other applications to take errant and unintended actions.
If needed your own programs can use inter-process communication if the server and client applications know what is and should be expected.
OLE automation is the normal way processes communicate with each other for fuctionality such as an excel spreadsheet in wordpad.
|
|