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 / C++ / MFC
  4. How to communicate between two different app using SendMessage API?

How to communicate between two different app using SendMessage API?

Scheduled Pinned Locked Moved C / C++ / MFC
c++jsontutorialquestion
13 Posts 6 Posters 3 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.
  • L Lost User

    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.

    A Offline
    A Offline
    Anasuya2015
    wrote on last edited by
    #3

    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.

    L D 2 Replies Last reply
    0
    • A Anasuya2015

      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.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #4

      The LPARAM in your sending application is a Unicode string, so why are you casting it to a MSG pointer in the receiving app?

      A 1 Reply Last reply
      0
      • A Anasuya2015

        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.

        A Offline
        A Offline
        Arthur V Ratz
        wrote on last edited by
        #5

        You can use COM automation, Named Pipes, TCP/IP Sockets or whatsoever by implementing your own protocol for interprocess communtication. :)

        A 1 Reply Last reply
        0
        • L Lost User

          The LPARAM in your sending application is a Unicode string, so why are you casting it to a MSG pointer in the receiving app?

          A Offline
          A Offline
          Anasuya2015
          wrote on last edited by
          #6

          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?

          L 1 Reply Last reply
          0
          • A Arthur V Ratz

            You can use COM automation, Named Pipes, TCP/IP Sockets or whatsoever by implementing your own protocol for interprocess communtication. :)

            A Offline
            A Offline
            Anasuya2015
            wrote on last edited by
            #7

            Here requirement is restrict to SendMessage() API. Anyway thanks for your answer. Can you send any sample code for Named Pipes implementation?

            A 2 Replies Last reply
            0
            • A Anasuya2015

              Here requirement is restrict to SendMessage() API. Anyway thanks for your answer. Can you send any sample code for Named Pipes implementation?

              A Offline
              A Offline
              Arthur V Ratz
              wrote on last edited by
              #8

              Using Pipes - MSDN Resource

              1 Reply Last reply
              0
              • A Anasuya2015

                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?

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #9

                Anasuya2015 wrote:

                So you mean to say ...

                No, I am saying that whatever type you use in the LPARAM field in the sending app, you must use the same type in the receiver.

                1 Reply Last reply
                0
                • A Anasuya2015

                  Here requirement is restrict to SendMessage() API. Anyway thanks for your answer. Can you send any sample code for Named Pipes implementation?

                  A Offline
                  A Offline
                  Arthur V Ratz
                  wrote on last edited by
                  #10

                  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. :)

                  1 Reply Last reply
                  0
                  • A Anasuya2015

                    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.

                    S Offline
                    S Offline
                    Serkan Onat
                    wrote on last edited by
                    #11

                    You can use WM_COPYDATA[^] message with SendMessage API There is a linked example on MSDN topic as well

                    M 1 Reply Last reply
                    0
                    • A Anasuya2015

                      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.

                      D Offline
                      D Offline
                      David Crow
                      wrote on last edited by
                      #12

                      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

                      1 Reply Last reply
                      0
                      • S Serkan Onat

                        You can use WM_COPYDATA[^] message with SendMessage API There is a linked example on MSDN topic as well

                        M Offline
                        M Offline
                        Maximilien
                        wrote on last edited by
                        #13

                        :thumbsup: This is what we use and it works nicely

                        I'd rather be phishing!

                        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