Exemplo n.º 1
0
        public static void SendMessageToWindow(IntPtr window, string message)
        {
            IntPtr ptrCopyData = IntPtr.Zero;

            try
            {
                NativeMethods.COPYDATASTRUCT copyData = new NativeMethods.COPYDATASTRUCT
                {
                    dwData = new IntPtr(0),
                    cbData = message.Length + 1,
                    lpData = Marshal.StringToHGlobalAnsi(message)
                };

                ptrCopyData = Marshal.AllocCoTaskMem(Marshal.SizeOf(copyData));
                Marshal.StructureToPtr(copyData, ptrCopyData, false);

                NativeMethods.SendMessage(window, NativeMethods.WM_COPYDATA, IntPtr.Zero, ptrCopyData);
            }
            finally
            {
                if (ptrCopyData != IntPtr.Zero)
                {
                    Marshal.FreeCoTaskMem(ptrCopyData);
                }
            }
        }
Exemplo n.º 2
0
 public static string ConvertMessageToText(IntPtr message)
 {
     NativeMethods.COPYDATASTRUCT copyData = (NativeMethods.COPYDATASTRUCT)Marshal.PtrToStructure(
         message, typeof(NativeMethods.COPYDATASTRUCT));
     return(Marshal.PtrToStringAnsi(copyData.lpData));
 }