Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Using GetMessage in C#

Using GetMessage in C#

Scheduled Pinned Locked Moved C#
helpcsharpc++tutorialquestion
12 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G gapfulgence

    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 !

    K Offline
    K Offline
    kubben
    wrote on last edited by
    #2

    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

    G 1 Reply Last reply
    0
    • K kubben

      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

      G Offline
      G Offline
      gapfulgence
      wrote on last edited by
      #3

      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 !

      K 1 Reply Last reply
      0
      • G gapfulgence

        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 !

        K Offline
        K Offline
        kubben
        wrote on last edited by
        #4

        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

        G B 2 Replies Last reply
        0
        • K kubben

          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

          G Offline
          G Offline
          gapfulgence
          wrote on last edited by
          #5

          Thanks Kubben ! Pat.

          p.f. Goudjo-Ako Bringing our energy together !

          1 Reply Last reply
          0
          • K kubben

            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

            B Offline
            B Offline
            baranils
            wrote on last edited by
            #6

            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);
            
            K 1 Reply Last reply
            0
            • B baranils

              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);
              
              K Offline
              K Offline
              kubben
              wrote on last edited by
              #7

              First I need to ask why you want to use sendmessage to communicate between to applications. There are better ways of doing this. Ben

              B 1 Reply Last reply
              0
              • K kubben

                First I need to ask why you want to use sendmessage to communicate between to applications. There are better ways of doing this. Ben

                B Offline
                B Offline
                baranils
                wrote on last edited by
                #8

                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

                K 1 Reply Last reply
                0
                • B baranils

                  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

                  K Offline
                  K Offline
                  kubben
                  wrote on last edited by
                  #9

                  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

                  B 1 Reply Last reply
                  0
                  • K kubben

                    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

                    B Offline
                    B Offline
                    baranils
                    wrote on last edited by
                    #10

                    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"

                    K 1 Reply Last reply
                    0
                    • B baranils

                      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"

                      K Offline
                      K Offline
                      kubben
                      wrote on last edited by
                      #11

                      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

                      B 1 Reply Last reply
                      0
                      • K kubben

                        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

                        B Offline
                        B Offline
                        baranils
                        wrote on last edited by
                        #12

                        Thank you I'll let you now

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups