How to communicate between two different app using SendMessage API?
-
How to communicate between two different app using Send Message API? Ex: APP1 having textbox txtBox1 APP2 having textbox txtBox2 In txtbox1 whats ever we type, that needs to be displayed in textbox2. How to achieve it using SendMessage() API. Ex code in VC++ is appreciated.
See SendMessage function (Windows)[^]. Use the RegisterWindowMessage function (Windows)[^] to create a message number that is unique to your applications, and set the other two parameters to values that both your applications understand.
-
See SendMessage function (Windows)[^]. Use the RegisterWindowMessage function (Windows)[^] to create a message number that is unique to your applications, and set the other two parameters to values that both your applications understand.
Thanks for your help. I am facing issue in extracting the message. Code is as follows... APP1:
int WM_MYMSG = RegisterWindowMessage (L"MYMESSAGE");
HWND hw = FindWindow(NULL, L"Demo");
LPCTSTR strMsg = L"ClientDemo1";
//Send that message
::SendMessage(hw, WM_MYMSG, NULL, (LPARAM(LPCTSTR)strMsg);APP2:
LRESULT CDemoDlg::OnMyMsg(WPARAM w, LPARAM l) {
MSG\* p = (MSG\*)l; LPCTSTR str = (LPCTSTR)p->message; MessageBox(str);// No message. But getting the alert while sending message. Need to extract the actual msg here. return (LRESULT) 0;
}
Please let me know what changes is needed here by which it'll display "ClientDemo1" in msgbox.
-
Thanks for your help. I am facing issue in extracting the message. Code is as follows... APP1:
int WM_MYMSG = RegisterWindowMessage (L"MYMESSAGE");
HWND hw = FindWindow(NULL, L"Demo");
LPCTSTR strMsg = L"ClientDemo1";
//Send that message
::SendMessage(hw, WM_MYMSG, NULL, (LPARAM(LPCTSTR)strMsg);APP2:
LRESULT CDemoDlg::OnMyMsg(WPARAM w, LPARAM l) {
MSG\* p = (MSG\*)l; LPCTSTR str = (LPCTSTR)p->message; MessageBox(str);// No message. But getting the alert while sending message. Need to extract the actual msg here. return (LRESULT) 0;
}
Please let me know what changes is needed here by which it'll display "ClientDemo1" in msgbox.
-
How to communicate between two different app using Send Message API? Ex: APP1 having textbox txtBox1 APP2 having textbox txtBox2 In txtbox1 whats ever we type, that needs to be displayed in textbox2. How to achieve it using SendMessage() API. Ex code in VC++ is appreciated.
You can use COM automation, Named Pipes, TCP/IP Sockets or whatsoever by implementing your own protocol for interprocess communtication. :)
-
The
LPARAM
in your sending application is a Unicode string, so why are you casting it to aMSG
pointer in the receiving app?I am just finding the way to print the message. So you mean to say it is not needed and directly we can use lparam to print the message?
-
You can use COM automation, Named Pipes, TCP/IP Sockets or whatsoever by implementing your own protocol for interprocess communtication. :)
Here requirement is restrict to SendMessage() API. Anyway thanks for your answer. Can you send any sample code for Named Pipes implementation?
-
Here requirement is restrict to SendMessage() API. Anyway thanks for your answer. Can you send any sample code for Named Pipes implementation?
-
I am just finding the way to print the message. So you mean to say it is not needed and directly we can use lparam to print the message?
-
Here requirement is restrict to SendMessage() API. Anyway thanks for your answer. Can you send any sample code for Named Pipes implementation?
Also you can reuse SendMessage() API function with its regular list of arguments by implementing your own that encapsulates for example named pipes client mechanism. :)
-
How to communicate between two different app using Send Message API? Ex: APP1 having textbox txtBox1 APP2 having textbox txtBox2 In txtbox1 whats ever we type, that needs to be displayed in textbox2. How to achieve it using SendMessage() API. Ex code in VC++ is appreciated.
You can use WM_COPYDATA[^] message with SendMessage API There is a linked example on MSDN topic as well
-
Thanks for your help. I am facing issue in extracting the message. Code is as follows... APP1:
int WM_MYMSG = RegisterWindowMessage (L"MYMESSAGE");
HWND hw = FindWindow(NULL, L"Demo");
LPCTSTR strMsg = L"ClientDemo1";
//Send that message
::SendMessage(hw, WM_MYMSG, NULL, (LPARAM(LPCTSTR)strMsg);APP2:
LRESULT CDemoDlg::OnMyMsg(WPARAM w, LPARAM l) {
MSG\* p = (MSG\*)l; LPCTSTR str = (LPCTSTR)p->message; MessageBox(str);// No message. But getting the alert while sending message. Need to extract the actual msg here. return (LRESULT) 0;
}
Please let me know what changes is needed here by which it'll display "ClientDemo1" in msgbox.
Your casting is a bit unclear. It should probably be:
::SendMessage(hw, WM_MYMSG, NULL, (LPARAM) strMsg);
...
LPCTSTR str = (LPCTSTR) l;
MessageBox(str);The process calling
SendMessage()
will likely be blocked by the second process since it will be waiting on the message box to be dismissed."One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
-
You can use WM_COPYDATA[^] message with SendMessage API There is a linked example on MSDN topic as well
:thumbsup: This is what we use and it works nicely
I'd rather be phishing!