private void VirtualChannelInitEventProc(IntPtr initHandle, ChannelEvents Event, byte[] data, int dataLength) { Debug.Print(DateTime.Now + " " + Environment.MachineName + ": VirtualChannelInitEventProc: " + Event); switch (Event) { case ChannelEvents.Initialized: break; case ChannelEvents.Connected: var ret = entryPoints.VirtualChannelOpen(initHandle, ref OpenChannel, ChannelMessage.ChannelName, channelOpenEventDelegate); if (ret != ChannelReturnCodes.Ok) { MessageBox.Show("TSTunnels: Open of RDP virtual channel failed.\n" + ret, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { /*main = new frmMain(entryPoints, OpenChannel); * main.Show(); * main.Hide(); * string servername = System.Text.Encoding.Unicode.GetString(data); * servername = servername.Substring(0, servername.IndexOf('\0')); * main.Text = "TS addin in C#: " + servername;*/ } break; case ChannelEvents.V1Connected: MessageBox.Show("TSTunnels: Connecting to a non Windows 2000 Terminal Server.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); break; case ChannelEvents.Disconnected: //main.RealClosing = true; //main.Close(); break; case ChannelEvents.Terminated: break; } }
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; } }