using System.Runtime.InteropServices;
[DllImport("User32.dll", EntryPoint = "FindWindow")] private static extern IntPtr FindWindow(string lpClassName, string lpWindowName); [DllImport("User32.dll", EntryPoint = "SendMessage")] //用于发送信息给窗体 private static extern int SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, ref COPYDATASTRUCT lParam); [StructLayout(LayoutKind.Sequential)] public struct COPYDATASTRUCT { public IntPtr dwData; public int cbData; public IntPtr lpData; }
COPYDATASTRUCT cds; string a = "032"; byte[] sarr = System.Text.Encoding.Default.GetBytes(a); cds.dwData = (IntPtr)0; cds.cbData = a.Length; cds.lpData = Marshal.AllocHGlobal(sarr.Length); Marshal.Copy(sarr, 0, cds.lpData, sarr.Length); IntPtr p = FindWindow("#32770", "GetMessage"); SendMessage(p, 0x004A, (IntPtr)0,ref cds); C# 发送WM_COPYDATA消息--网络COPY供个人参考
原文:http://www.cnblogs.com/ande/p/4491493.html