Top > .NET > WM_COPYDATA
        const int WM_COPYDATA = 0x4a;
        public struct COPYDATASTRUCT
        {
            public IntPtr dwData;
            public int cbData;
            public IntPtr lpData;
        }

        [DllImport("user32", EntryPoint = "SendMessage")]
        public static extern int SendMessageCds(IntPtr h, uint m, IntPtr wp, ref COPYDATASTRUCT cds);

        private void button1_Click(object sender, System.EventArgs e)
        {
            string s = @"こんにちは";        // 送る文字列
            IntPtr hwnd = this.Handle;      // 送り先

            byte[] bytes = System.Text.Encoding.Default.GetBytes(s);
            IntPtr pBytes = Marshal.AllocHGlobal(bytes.Length);
            Marshal.Copy(bytes, 0, pBytes, bytes.Length);

            COPYDATASTRUCT cds = new COPYDATASTRUCT();
            cds.lpData = pBytes;
            cds.cbData = bytes.Length;

            SendMessageCds(hwnd, WM_COPYDATA, Handle, ref cds);

            Marshal.FreeHGlobal(pBytes);
        }

        protected override void WndProc(ref Message m)
        {
            if (m.Msg == WM_COPYDATA)
            {
                COPYDATASTRUCT cds = (COPYDATASTRUCT)Marshal.PtrToStructure(m.LParam,
                  typeof(COPYDATASTRUCT));
                byte[] bytes = new byte[cds.cbData];
                Marshal.Copy(cds.lpData, bytes, 0, cds.cbData);
                string s = System.Text.Encoding.Default.GetString(bytes);
                //string s = Marshal.PtrToStringAuto(cds.lpData, cds.cbData);
                Debug.Print("[" + s + "]");
            }
            base.WndProc(ref m);
        }


URL B I U SIZE Black Maroon Green Olive Navy Purple Teal Gray Silver Red Lime Yellow Blue Fuchsia Aqua White

Reload   New Lower page making Edit Freeze Diff Upload Copy Rename   Front page List of pages Search Recent changes Backup Referer   Help   RSS of recent changes