/// <summary> /// Sends text to recipient window adding sender address in it /// </summary> /// <param name="sender"></param> /// <param name="recipient"></param> /// <param name="text"></param> public static void SendText(IntPtr sender, IntPtr recipient, string text) { Debug.Assert(recipient != IntPtr.Zero, "Recipient hWnd my not be zero"); Debug.Assert(!string.IsNullOrEmpty(text), "Send text may not be empty"); user32.CopyDataStruct cds = new user32.CopyDataStruct(); try { string newText = string.Format("{0}!{1}", sender, text); cds.cbData = (newText.Length + 1) * 2; cds.lpData = user32.LocalAlloc(0x40, cds.cbData); Marshal.Copy(newText.ToCharArray(), 0, cds.lpData, newText.Length); cds.dwData = (IntPtr)1; user32.SendMessage(recipient, user32.WM_COPYDATA, IntPtr.Zero, ref cds); } finally { cds.Dispose(); } }