public void VirtualChannelWrite(byte[] data)
        {
            ChannelReturnCodes ret = _entryPoints.
                                     VirtualChannelWrite(_openChannel, data, (uint)data.Length, IntPtr.Zero);

            if (ret != ChannelReturnCodes.Ok)
            {
                throw new VirtualChannelException(String.Format("TsClientAddIn ({0}): Couldn't write to communcation channel for battery monitor.", _channelName));
            }
        }
        public void VirtualChannelInitEventProc(IntPtr initHandle,
                                                ChannelEvents Event, byte[] data, int dataLength)
        {
            switch (Event)
            {
            case ChannelEvents.Initialized:
                break;

            case ChannelEvents.Connected:
                ChannelReturnCodes ret = _entryPoints.VirtualChannelOpen(
                    initHandle, ref _openChannel,
                    _channelName, _channelOpenEventDelegate);
                if (ret != ChannelReturnCodes.Ok)
                {
                    throw new VirtualChannelException(String.Format("TsClientAddIn ({0}): Couldn't open communcation channel for battery monitor.", _channelName));
                }
                else
                {
                    string servername = System.Text.Encoding.Unicode.GetString(data);
                    _serverName = servername.Substring(0, servername.IndexOf('\0'));
                }
                break;

            case ChannelEvents.V1Connected:
                throw new VirtualChannelException(String.Format("TsClientAddIn ({0}): Connecting to a Terminal Server that doesn't support data communication.", _channelName));

            case ChannelEvents.Disconnected:
                break;

            case ChannelEvents.Terminated:
                GC.KeepAlive(_channelInitEventDelegate);
                GC.KeepAlive(_channelOpenEventDelegate);
                GC.KeepAlive(_entryPoints);
                GC.Collect();
                GC.WaitForPendingFinalizers();
                break;
            }
        }