CodeForge.comFree Open Source Codes Forge and Sharing |
using System;
using System.Collections;
using System.IO;
using System.Runtime.InteropServices;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Windows.Forms;
using Manas;
namespace vbAccelerator.Components.Win32
{
public delegate void DataReceivedEventHandler(object sender, DataReceivedEventArgs e);
/// <summary>
/// A class which wraps using Windows native WM_COPYDATA
/// message to send interprocess data between applications.
/// This is a simple technique for interprocess data sends
/// using Windows. The alternative to this is to use
/// Remoting, which requires a network card and a way
/// to register the Remoting name of an object so it
/// can be read by other applications.
/// </summary>
public class CopyData : NativeWindow, IDisposable
{
/// <summary>
/// Event raised when data is received on any of the channels
/// this class is subscribed to.
/// </summary>
public event DataReceivedEventHandler DataReceived;
[StructLayout(LayoutKind.Sequential)]
private struct COPYDATASTRUCT
{
public IntPtr dwData;
public int cbData;
public IntPtr lpData;
}
private const int WM_COPYDATA = 0x4A;
private const int WM_DESTROY = 0x2;
#region Member Variables
private CopyDataChannels channels = null;
private bool disposed = false;
#endregion
/// <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);
...
...
... to be continued.
This is a preview. To get the complete source file,
please click here to download the whole source code package.
| Name | Size | Date |
| 1.00 B | ||
| 1.00 B | ||
| 353.00 B | 02-08-08 12:57 | |
| 1.90 kB | 02-08-08 12:57 | |
| 188.00 B | 02-08-08 12:57 | |
| 423.00 kB | 02-08-08 16:15 | |
| 876.00 B | 02-08-08 12:56 | |
| 7.97 kB | 02-08-08 16:15 | |
| 51.00 B | 02-08-08 16:15 | |
| 1.01 kB | 02-08-08 16:11 | |
| 3.60 kB | 02-08-08 16:15 | |
| 51.00 B | 02-08-08 16:12 | |
| 1.01 kB | 02-08-08 16:11 | |
| 3.70 kB | 02-08-08 16:12 | |
| 128.00 kB | 02-08-08 16:05 | |
| 894.00 B | 02-08-08 14:44 | |
| 309.50 kB | 02-08-08 16:05 | |
| 5.50 kB | 09-23-05 07:56 | |
| 894.00 B | 02-08-08 14:44 | |
| 1.00 B | ||
| 894.00 B | 02-08-08 14:44 | |
| 1.00 B | ||
| 1.00 B | ||
| 168.00 kB | 02-08-08 12:44 | |
| 1.11 kB | 02-08-08 11:44 | |
| 347.50 kB | 02-08-08 12:44 | |
| 943.00 B | 07-19-06 17:16 | |
| 14.90 kB | 02-08-08 14:59 | |
| 1.12 kB | 06-08-06 17:12 | |
| 13.01 kB | 06-08-06 17:08 | |
| 11.29 kB | 02-08-08 16:05 | |
| 3.65 kB | 02-08-08 14:58 | |
| 5.68 kB | 02-08-08 14:58 | |
| 1.00 B | ||
| 1.00 B | ||
| 12.00 B | ||
| 7.65 kB | 02-08-08 11:47 | |
| 1.00 B | ||
| 5.50 kB | 02-08-08 14:21 | |
| 40.00 kB | 02-08-08 14:21 | |
| 108.00 kB | 02-08-08 14:29 | |
| 32.00 kB | 06-10-06 10:22 | |
| 920.00 B | 02-08-08 14:59 | |
| 128.00 kB | 02-08-08 16:05 | |
| 180.00 B | 02-08-08 14:59 | |
| 309.50 kB | 02-08-08 16:05 | |
| 180.00 B | 02-08-08 14:10 | |
| 920.00 B | 02-08-08 12:08 | |
| 1.64 kB | 02-08-08 16:05 | |
| 428.00 B | 10-30-06 16:41 | |
| 1.19 kB | 02-08-08 13:20 | |
| 488.00 B | 02-08-08 14:12 | |
| 1.00 B | ||
| 1.26 kB | 02-08-08 14:33 | |
| 2.80 kB | 02-08-08 14:08 | |
| 5.48 kB | 06-10-06 10:19 | |
| 1.64 kB | 02-08-08 14:44 | |
| 507.00 B | 02-08-08 14:44 | |
| 6.49 kB | 02-08-08 14:18 | |
| 0.00 B | 01-02-09 16:33 | |
| 0.00 B | 01-02-09 16:33 | |
| 637.00 B | 02-08-08 14:21 | |
| 651.00 B | 02-08-08 14:21 | |
| 629.00 B | 02-08-08 14:21 | |
| 631.00 B | 02-08-08 14:21 | |
| 647.00 B | 02-08-08 14:21 | |
| 629.00 B | 02-08-08 14:21 | |
| 651.00 B | 02-08-08 14:21 | |
| 631.00 B | 02-08-08 14:21 | |
| 635.00 B | 02-08-08 14:21 | |
| 637.00 B | 02-08-08 14:21 | |
| 639.00 B | 02-08-08 14:21 | |
| 645.00 B | 02-08-08 14:21 | |
| 663.00 B | 02-08-08 14:21 | |
| 637.00 B | 02-08-08 14:21 | |
| 639.00 B | 02-08-08 14:21 | |
| 745.00 B | 02-08-08 14:21 | |
| 104.22 kB | 02-08-08 14:21 | |
| 637.00 B | 02-08-08 14:21 | |
| 653.00 B | 02-08-08 14:21 | |
| 647.00 B | 02-08-08 14:21 | |
| 639.00 B | 02-08-08 14:21 | |
| 645.00 B | 02-08-08 14:21 | |
| 205.96 kB | 02-08-08 14:29 | |
| 588.00 B | 02-08-08 14:21 | |
| 651.00 B | 02-08-08 14:21 | |
| 7.66 kB | 02-08-08 14:44 | |
| 634.00 B | 02-08-08 11:46 | |
| 926.00 B | 02-08-08 14:29 | |
| 36.50 kB | 02-08-08 15:56 |