Using GetMessage in C#
-
Hi, I'm working on inter-process communication between a C++ application and a C# application. I want to transfer string data between them. I'm being blocked by a problem: I don't know how to intercept data (sent from my C++ app) in my C# app. I read I can use GetMessage function, but I dont know how. Here is how I send data from my C++ app to my C# one: LRESULT copyDataResult; //CWnd *pOtherWnd = CWnd::FindWindow(NULL, m_otherAppHeader.GetBuffer(m_otherAppHeader.GetLength())); CWnd *pOtherWnd = CWnd::FindWindow(NULL, "EC"); m_otherAppHeader.ReleaseBuffer(); if (pOtherWnd) { // Say that we fount ExperienceCreator window AfxMessageBox("ExperienceCreator is opened."); COPYDATASTRUCT cpd; cpd.dwData = 0; CString txt; c_TxText.GetWindowText(txt); cpd.cbData = txt.GetLength() + 1 ; cpd.lpData = (void*)txt.GetBuffer(txt.GetLength() +1); copyDataResult = pOtherWnd->SendMessage(WM_COPYDATA, (WPARAM)AfxGetApp()->m_pMainWnd->GetSafeHwnd(),(LPARAM)&cpd); txt.ReleaseBuffer(); // copyDataResult has value returned by other app AfxMessageBox("Info has been sent to ExperienceCreator"); } else { //AfxMessageBox("Unable to find other application."); AfxMessageBox("Unable to find EC."); } Can you please help me for this problem ? Thanks.
p.f. Goudjo-Ako Bringing our energy together !
-
Hi, I'm working on inter-process communication between a C++ application and a C# application. I want to transfer string data between them. I'm being blocked by a problem: I don't know how to intercept data (sent from my C++ app) in my C# app. I read I can use GetMessage function, but I dont know how. Here is how I send data from my C++ app to my C# one: LRESULT copyDataResult; //CWnd *pOtherWnd = CWnd::FindWindow(NULL, m_otherAppHeader.GetBuffer(m_otherAppHeader.GetLength())); CWnd *pOtherWnd = CWnd::FindWindow(NULL, "EC"); m_otherAppHeader.ReleaseBuffer(); if (pOtherWnd) { // Say that we fount ExperienceCreator window AfxMessageBox("ExperienceCreator is opened."); COPYDATASTRUCT cpd; cpd.dwData = 0; CString txt; c_TxText.GetWindowText(txt); cpd.cbData = txt.GetLength() + 1 ; cpd.lpData = (void*)txt.GetBuffer(txt.GetLength() +1); copyDataResult = pOtherWnd->SendMessage(WM_COPYDATA, (WPARAM)AfxGetApp()->m_pMainWnd->GetSafeHwnd(),(LPARAM)&cpd); txt.ReleaseBuffer(); // copyDataResult has value returned by other app AfxMessageBox("Info has been sent to ExperienceCreator"); } else { //AfxMessageBox("Unable to find other application."); AfxMessageBox("Unable to find EC."); } Can you please help me for this problem ? Thanks.
p.f. Goudjo-Ako Bringing our energy together !
-
Just curious why would you want to send a string message between the applications? Sending windows messages would be much more standard way of communicating between applications. Ben
You're right. I didn't explain myself correctly. What I want to do is send string data using windows messages. Thanks !
p.f. Goudjo-Ako Bringing our energy together !
-
You're right. I didn't explain myself correctly. What I want to do is send string data using windows messages. Thanks !
p.f. Goudjo-Ako Bringing our energy together !
-
Here is an article I wrote that has two .net applications sending and receiving windows messages. http://www.codeproject.com/dotnet/windowsappsingleinstance.asp[^] Hope that helps. Ben
Thanks Kubben ! Pat.
p.f. Goudjo-Ako Bringing our energy together !
-
Here is an article I wrote that has two .net applications sending and receiving windows messages. http://www.codeproject.com/dotnet/windowsappsingleinstance.asp[^] Hope that helps. Ben
Hello I've seen your article but I still do not understand How can I intercept a message into one c# application the message will be send from another csharp application using user32.dll API
\[DllImport("user32.dll")\] static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, \[MarshalAs(UnmanagedType.LPStr)\] string lParam);
-
Hello I've seen your article but I still do not understand How can I intercept a message into one c# application the message will be send from another csharp application using user32.dll API
\[DllImport("user32.dll")\] static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, \[MarshalAs(UnmanagedType.LPStr)\] string lParam);
-
First I need to ask why you want to use sendmessage to communicate between to applications. There are better ways of doing this. Ben
-
Hello Thank for your reply No particular reason I just need the best way to send string parameter from one running .NET app to another running one The second should trigger an event when receiving a message
Well, If you just want it to trigger an event in the second app, they my article should work ok. Windows message won't allow you to pass a string in. So if the string it self is important you will have to do something different. If the string has certain characters that should cause something to trigger in the second app, you can just check for those in the first app and then send a windows message. Let me know if the string is important to the second app or not. Ben
-
Well, If you just want it to trigger an event in the second app, they my article should work ok. Windows message won't allow you to pass a string in. So if the string it self is important you will have to do something different. If the string has certain characters that should cause something to trigger in the second app, you can just check for those in the first app and then send a windows message. Let me know if the string is important to the second app or not. Ben
Hello Kubben Yes the string is important APP A (.NET) is running APP A require a Form from APP B (.NET) To show user "abc" So I check if APP B is already running If NO : I launch it using Process.Start("APP B","abc"); If YES : I want to trigger an event for APP B to show user "abc"
-
Hello Kubben Yes the string is important APP A (.NET) is running APP A require a Form from APP B (.NET) To show user "abc" So I check if APP B is already running If NO : I launch it using Process.Start("APP B","abc"); If YES : I want to trigger an event for APP B to show user "abc"
Well, You can try using FindWindow to get the second app windows handle. Then you should be able to send a string to it. There are some examples out there. I found this one: http://social.msdn.microsoft.com/forums/en-US/vbinterop/thread/62d0c25f-dadb-4b24-9679-f9f75717456c/ Hopefully, that helps. Ben
-
Well, You can try using FindWindow to get the second app windows handle. Then you should be able to send a string to it. There are some examples out there. I found this one: http://social.msdn.microsoft.com/forums/en-US/vbinterop/thread/62d0c25f-dadb-4b24-9679-f9f75717456c/ Hopefully, that helps. Ben