Nothing2Lose Posted August 13, 2010 Posted August 13, 2010 Hi! I have searched on the Internet but it doesn't match my purpose. I wonder that how to send a message to a process. For example: I have 2 program ( A & B ) and a text file ©. A are in process but B not. When user open C, system will active B and B will have a command line ($CmdLine) including C address. I want B to send that to A and A will read C data. Do you have an idea? Thank you very much!!! o:)
Tvern Posted August 13, 2010 Posted August 13, 2010 Are (A) and/or ( programs you have written yourself? If they are 3rd party apps, could you specify them? The way you can interact with a program depends on the program, so it's vital to know what you are working with to help you.
Nothing2Lose Posted August 13, 2010 Author Posted August 13, 2010 Are (A) and/or ( programs you have written yourself?If they are 3rd party apps, could you specify them?The way you can interact with a program depends on the program, so it's vital to know what you are working with to help you.Oh, yes! Both are written by me. Do you have a suggestion???
Tvern Posted August 13, 2010 Posted August 13, 2010 In that case there are a lot of ways to do it. The easiest way is probably to: * Add an Iniwrite() to program B, to write the path to a set file, in a set location. * Give A a function that runs every second or so, by calling it from to a loop, or by using AdlibRegister() * Make the function check the given location for the file using FileExist() (optional) * Read the file using Iniread() * Delete the file using FileDelete()
Nothing2Lose Posted August 13, 2010 Author Posted August 13, 2010 In that case there are a lot of ways to do it. The easiest way is probably to:* Add an Iniwrite() to program B, to write the path to a set file, in a set location.* Give A a function that runs every second or so, by calling it from to a loop, or by using AdlibRegister()* Make the function check the given location for the file using FileExist() (optional)* Read the file using Iniread()* Delete the file using FileDelete()Thank you very much! Can you tell me how to send it directly?
Tvern Posted August 13, 2010 Posted August 13, 2010 Although there are loads of ways to get programs to comunicate I'm not completely sure how to do that. StdinWrite and StdoutRead would do pretty much what you want, but I don't know if they can be made to work unless one process runs the other. (It's probably possible, but I don't know how) The TCP functions will also be able to make the programs communicate without using a common file, but it's not really the intended purpose. You could use a registry key instead of a file, but that's not any more direct. The last option I can think of now is shared memory. I have know idea on how that works, but I there was a UDF for it a while ago in the example scripts forum. I'm sure you're not the only one that asked this, so if you search the forum you might find something that will help you.
Spiff59 Posted August 13, 2010 Posted August 13, 2010 Search on WM_USER or WM_APP if you don't need to pass more than two 32-bit integer values between the scripts. To exchange more data than that, look into the WM_COPYDATA message.
seandisanti Posted August 14, 2010 Posted August 14, 2010 Can you share some examples?if the values are being passed only as the program starts, command line parameters are probably a much easier way to go..
Nothing2Lose Posted August 14, 2010 Author Posted August 14, 2010 Can anyone tell me more about WM_COPYDATA message and some examples?
Spiff59 Posted August 14, 2010 Posted August 14, 2010 These are pretty basic examples of using the WM_COPYDATA functions found around the forums. Parent.au3 expandcollapse popup#include <WindowsConstants.au3> Global $hParent, $hChild, $received ; parent gui $hParent = GUICreate("Parent", 300, 120, 100) $input_send = GUICtrlCreateInput("", 10, 10, 280, 20) $btn = GUICtrlCreateButton("SEND TO CHILD", 80, 35, 140, 20, 0x0001) GUICtrlCreateLabel("RECEIVED FROM CHILD", 10, 75, 280, 20, 0x01) $input_received = GUICtrlCreateInput("", 10, 90, 280, 20, 0x0800) GUISetState(@SW_SHOW) ; launch child - trade handles GUIRegisterMsg($WM_COPYDATA, "WM_COPYDATA_ReceiveData") ; register WM_COPYDATA ShellExecute("child.exe", $hParent) ; start child process - send parent handle While Not $received ; wait for child process to return it's handle Sleep(50) WEnd $hChild = HWnd($received); assign child hamdle $received = "" ; main loop While 1 $msg = GUIGetMsg() If $msg = -3 Then ExitLoop If $msg = $btn Then WM_COPYDATA_SendData($hChild, GUICtrlRead($input_send)) ; send to child If $received Then GUICtrlSetData($input_received, $received) ; receive form child $received = "" EndIf WEnd ProcessClose("child.exe") Exit ;=================================================================================================================================== Func WM_COPYDATA_ReceiveData($hWnd, $MsgID, $wParam, $lParam) ; Local $tCOPYDATA = DllStructCreate("dword;dword;ptr", $lParam) Local $tMsg = DllStructCreate("char[" & DllStructGetData($tCOPYDATA, 2) & "]", DllStructGetData($tCOPYDATA, 3)) $received = DllStructGetData($tMsg, 1) EndFunc Func WM_COPYDATA_SendData($hWnd, $sData) Local $tCOPYDATA = DllStructCreate("dword;dword;ptr") Local $tMsg = DllStructCreate("char[" & StringLen($sData) + 1 & "]") DllStructSetData($tMsg, 1, $sData) DllStructSetData($tCOPYDATA, 2, StringLen($sData) + 1) DllStructSetData($tCOPYDATA, 3, DllStructGetPtr($tMsg)) $Ret = DllCall("user32.dll", "lparam", "SendMessage", "hwnd", $hWnd, "int", $WM_COPYDATA, "wparam", 0, "lparam", DllStructGetPtr($tCOPYDATA)) EndFunc Child.au3 expandcollapse popup#NoTrayIcon #include <WindowsConstants.au3> Global $hParent, $hChild, $received Global $hParent = HWnd($CmdLine[1]) ; get parent handle from commandline ; child gui $hChild = GUICreate("Child", 300, 150, 440, Default, 0x00800000) $input_send = GUICtrlCreateInput("", 10, 10, 280, 20) $btn = GUICtrlCreateButton("SEND TO PARENT", 80, 35, 140, 20, 0x0001) GUICtrlCreateLabel("RECEIVED FROM PARENT", 10, 75, 280, 20, 0x01) $input_received = GUICtrlCreateInput("", 10, 90, 280, 20, 0x0800) GUISetState(@SW_SHOW) GUIRegisterMsg($WM_COPYDATA, "WM_COPYDATA_ReceiveData") ; register WM_COPYDATA WM_COPYDATA_SendData($hParent, $hChild) ; return child handle to parent ; main loop While 1 $msg = GUIGetMsg() If $msg = $btn Then WM_COPYDATA_SendData($hParent, GUICtrlRead($input_send)) ; send to parent If $received Then GUICtrlSetData($input_received, $received) ; receive from parent $received = "" EndIf WEnd Exit ;=================================================================================================================================== Func WM_COPYDATA_ReceiveData($hWnd, $MsgID, $wParam, $lParam) ; Local $tCOPYDATA = DllStructCreate("dword;dword;ptr", $lParam) Local $tMsg = DllStructCreate("char[" & DllStructGetData($tCOPYDATA, 2) & "]", DllStructGetData($tCOPYDATA, 3)) $received = DllStructGetData($tMsg, 1) EndFunc Func WM_COPYDATA_SendData($hWnd, $sData) Local $tCOPYDATA = DllStructCreate("dword;dword;ptr") Local $tMsg = DllStructCreate("char[" & StringLen($sData) + 1 & "]") DllStructSetData($tMsg, 1, $sData) DllStructSetData($tCOPYDATA, 2, StringLen($sData) + 1) DllStructSetData($tCOPYDATA, 3, DllStructGetPtr($tMsg)) $Ret = DllCall("user32.dll", "lparam", "SendMessage", "hwnd", $hWnd, "int", $WM_COPYDATA, "wparam", 0, "lparam", DllStructGetPtr($tCOPYDATA)) EndFunc
Nothing2Lose Posted August 14, 2010 Author Posted August 14, 2010 (edited) Thank for all! All of your suggestions are so great! One more question! If the child window is hidden, may sending message be wrong??? And if true, how to fix it??? o:) Edited August 14, 2010 by Nothing2Lose
Spiff59 Posted August 14, 2010 Posted August 14, 2010 (edited) It still works with a process (or processes) hidden, as long as they have a GUI. Edited August 14, 2010 by Spiff59
Nothing2Lose Posted August 15, 2010 Author Posted August 15, 2010 It still works with a process (or processes) hidden, as long as they have a GUI.Thank for helping me!
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now