Esempio n. 1
0
        /// <summary>
        /// Override for a form's Window Procedure to handle WM_COPYDATA
        /// messages sent by other instances of this class.
        /// </summary>
        /// <param name="m">The Windows Message information.</param>
        protected override void WndProc(ref Message m)
        {
            if (m.Msg == WM_COPYDATA)
            {
                var cds = (COPYDATASTRUCT)Marshal.PtrToStructure(m.LParam, typeof(COPYDATASTRUCT));
                if (cds.cbData > 0)
                {
                    byte[] data = new byte[cds.cbData];
                    Marshal.Copy(cds.lpData, data, 0, cds.cbData);
                    MemoryStream       stream = new MemoryStream(data);
                    BinaryFormatter    b      = new BinaryFormatter();
                    CopyDataObjectData cdo    = (CopyDataObjectData)b.Deserialize(stream);

                    if (_channels != null && _channels.Contains(cdo.Channel))
                    {
                        CopyDataReceivedEventArgs d = new CopyDataReceivedEventArgs(cdo.Channel, cdo.Data, cdo.Sent);
                        OnCopyDataReceived(d);
                        m.Result = (IntPtr)1;
                    }
                }
            }
            else if (m.Msg == WM_DESTROY)
            {
                // WM_DESTROY fires before OnHandleChanged and is
                // a better place to ensure that we've cleared
                // everything up.
                _channels?.OnHandleChange();
                base.OnHandleChange();
            }
            base.WndProc(ref m);
        }
Esempio n. 2
0
        /// <summary>
        /// Override for a form's Window Procedure to handle WM_COPYDATA
        /// messages sent by other instances of this class.
        /// </summary>
        /// <param name="m">The Windows Message information.</param>
        protected override void WndProc(ref System.Windows.Forms.Message m )
        {
            if (m.Msg == WM_COPYDATA) {
                COPYDATASTRUCT cds = new COPYDATASTRUCT();
                cds = (COPYDATASTRUCT) Marshal.PtrToStructure(m.LParam, typeof(COPYDATASTRUCT));
                if (cds.cbData > 0) {
                    byte[] data = new byte[cds.cbData];
                    Marshal.Copy(cds.lpData, data, 0, cds.cbData);
                    MemoryStream stream = new MemoryStream(data);
                    BinaryFormatter b = new BinaryFormatter();
                    CopyDataObjectData cdo = (CopyDataObjectData) b.Deserialize(stream);

                    if (channels.Contains(cdo.Channel)) {
                        CopyDataReceivedEventArgs d = new CopyDataReceivedEventArgs(cdo.Channel, cdo.Data, cdo.Sent);
                        OnCopyDataReceived(d);
                        m.Result = (IntPtr) 1;
                    }
                }
            } else if (m.Msg == WM_DESTROY) {
                // WM_DESTROY fires before OnHandleChanged and is
                // a better place to ensure that we've cleared
                // everything up.
                channels.OnHandleChange();
                base.OnHandleChange();
            }
            base.WndProc(ref m);
        }
Esempio n. 3
0
 /// <summary>
 /// Raises the DataReceived event from this class.
 /// </summary>
 /// <param name="e">The data which has been received.</param>
 protected void OnCopyDataReceived(CopyDataReceivedEventArgs e)
 {
     CopyDataReceived(this, e);
 }
Esempio n. 4
0
 /// <summary>
 /// Raises the DataReceived event from this class.
 /// </summary>
 /// <param name="e">The data which has been received.</param>
 protected void OnCopyDataReceived(CopyDataReceivedEventArgs e)
 {
     CopyDataReceived?.Invoke(this, e);
 }
 /// <summary>
 /// DataReceivedEventHandler
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="dataReceivedEventArgs"></param>
 private void CopyDataDataReceived(object sender, CopyDataReceivedEventArgs copyDataReceivedEventArgs)
 {
     // Cast the data to the type of object we sent:
     CopyDataTransport dataTransport = (CopyDataTransport)copyDataReceivedEventArgs.Data;
     HandleDataTransport(dataTransport);
 }