0

I used this code in the server side

    void Window_Loaded(object sender, RoutedEventArgs e)
    {

        HwndSource source = HwndSource.FromHwnd(new WindowInteropHelper(this).Handle);
        source.AddHook(new HwndSourceHook(WndProc));

    }
    private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
    {
        // Handle messages...

            var htLocation = DefWindowProc(hwnd, msg, wParam, lParam).ToInt32();

            if (msg == 1)
            {
            MessageBox.Show("" + msg);
            }


        return new IntPtr(1);
    }

And I send the message from the client side like this

SendMessage(m_Process.MainWindowHandle, 1, (IntPtr)(-1), (IntPtr)(-1));

The problem is that the server side cannot receive this message, why?

jignesh Vadadoriya
  • 3,244
  • 3
  • 18
  • 29
MElagder
  • 29
  • 2
  • 4
  • 1
    Side note: Why do you have this: `"" + msg` and not something clearer like `msg.ToString()`? – TheLethalCoder Dec 14 '16 at 12:32
  • thanks for this note – MElagder Dec 14 '16 at 13:00
  • Are you sure you are sending to the correct window? I had issues where the WPF process had multiple window handles. Try: https://msdn.microsoft.com/en-us/library/ms633497(VS.85).aspx – Chrille Dec 14 '16 at 13:09
  • yes i have two wpf applications, one start the other (client one start the server one), client now has pointer of the server & should send message correctly to the server – MElagder Dec 14 '16 at 13:22
  • Check [this](https://social.msdn.microsoft.com/Forums/en-US/6c947148-587e-4602-aa17-4769ea9bf27d/how-to-pass-value-between-two-process-net-c-exe?forum=csharpgeneral) out. – Abin Dec 14 '16 at 14:23
  • check [this](http://stackoverflow.com/a/10390858/2470362) too... – Abin Dec 14 '16 at 14:29

1 Answers1

1

I found the mistake

the message id I sent must be 0x0112 not 1 this is for windows command

MElagder
  • 29
  • 2
  • 4