SendMessage without waiting or PostMessage with Data

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • alag20
    New Member
    • Apr 2007
    • 84

    SendMessage without waiting or PostMessage with Data

    Hi Guys,
    I need to send a string from c# application to another c# Application.

    On receiving application side the code i have is below.

    Code:
     protected override void WndProc(ref Message m)
            {
                switch (m.Msg)
                {
                    case (int)Msg.WM_USER:
                        break;
                    case (int)Msg.WM_COPYDATA:
                        COPYDATASTRUCT mystr = new COPYDATASTRUCT();
                        Type mytype = mystr.GetType();
                        mystr = (COPYDATASTRUCT) m.GetLParam(mytype);
                        //Here is where i want to do my processing but return the result
                        //to calling application.
                        break;
                }
    
                base.WndProc(ref m);
            }

    Ideally i dont want to wait after extracting mystr for results to be returned, i just want it to act like PostMessage. The reason i cant use PostMessage is because it doesnt work with WM_COPYDATA. Please help guys!!!!!!!!!!! !
  • alag20
    New Member
    • Apr 2007
    • 84

    #2
    Okay guys!
    After another day of messing around, i finally found the solution.

    I am posting it here in case anyone else might need it as well.

    You basically need to use ReplyMessage in Win32.dll in WndProc as shown below.

    Code:
     protected override void WndProc(ref Message m)
            {
                switch (m.Msg)
                {
                    case (int)Msg.WM_USER:
                        break;
                    case (int)Msg.WM_COPYDATA:
                        COPYDATASTRUCT mystr = new COPYDATASTRUCT();
                        Type mytype = mystr.GetType();
                        mystr = (COPYDATASTRUCT) m.GetLParam(mytype);
                        if (Win32.InSendMessage())
                            Win32.ReplyMessage(IntPtr.Zero); //Returns 0 to calling application
                        //Do your stuff here
                        break;
                }
    
                base.WndProc(ref m);
            }

    Comment

    • GaryTexmo
      Recognized Expert Top Contributor
      • Jul 2009
      • 1501

      #3
      I have no idea about any of this, I just wanted to say thanks for updating with your solution. This site seems to get a lot of google hits, so having this here is bound to help someone :)

      Comment

      Working...