public partial class Form1 : Form { String data = "my message"; public const int WM_COPYDATA = 0x4A; int iHandle; COPYDATASTRUCT cds; [StructLayout(LayoutKind.Sequential)] struct COPYDATASTRUCT { public int dwData; public int cbData; public int lpData; } [DllImport("user32.dll")] public static extern int FindWindow(string lpClassName, string lpWindowName); [DllImport("user32.dll",CharSet=CharSet.Auto)] private static extern int SendMessage(int hWnd, int wMsg, int wParam, COPYDATASTRUCT lParam); [DllImport("kernel32.dll")] public static extern void CopyMemory(byte dst, string src, int len); public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { iHandle = FindWindow(null, "window_name"); COPYDATASTRUCT cds; cds.dwData = 1; cds.cbData = data.Length; cds.lpData = VarPtr(data); } public static byte[] StrToByteArray(string str) { System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding(); return encoding.GetBytes(str); } public int VarPtr(object e) { GCHandle GC = GCHandle.Alloc(e, GCHandleType.Pinned); //int gc = GC.AddrOfPinnedObject().ToInt32(); int gc = GC.AddrOfPinnedObject().ToInt32(); GC.Free(); return gc; } private void button1_Click(object sender, EventArgs e) { SendMessage(iHandle, WM_COPYDATA, 0, cds); } }