Pevus
Pevus

Reputation: 173

IPC in C#, sending text from one exe to another exe

I would like to send a message from a WPF application's textbox to an open notepad. After I click the button next to the the textbox, I would like the content is written into the notepad, I mean.

How can I send messages between 2 different applications ?

Upvotes: 3

Views: 2671

Answers (2)

Nick Sinas
Nick Sinas

Reputation: 2634

[DllImport("user32.dll", EntryPoint = "FindWindowEx")]
public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);

[DllImport("User32.dll")]
public static extern int SendMessage(IntPtr hWnd, int uMsg, int wParam, string lParam);

private static void DoSendMessage(string message)
{
    Process notepad = Process.Start(new ProcessStartInfo("notepad.exe"));
    notepad.WaitForInputIdle();

    if (notepad != null)
    {
        IntPtr child = FindWindowEx(notepad.MainWindowHandle, new IntPtr(0), "Edit", null);
        SendMessage(child, 0x000C, 0, message);
    }
}

Upvotes: 2

tom502
tom502

Reputation: 701

For sending data between two applications you control, you could use NamedPipeClientStream and NamedPipeServerStream

Upvotes: 1

Related Questions