refer http://blogs.msdn.com/b/rds/archive/2007/09/20/dynamic-virtual-channels.aspx

An important goal of the Terminal Services (TS) team is to provide a product that can easily be extended by third parties to better meet their needs.  While TS has always supported virtual channels, they had their limitations, including the limited number of channels and the difficulty involved in writing virtual channel applications.  For the 6.1 version of the client, and Windows Vista SP1 or Windows Server 2008 on the server side, Dynamic Virtual Channels (DVCs) can be used. DVCs address the limitations of the old virtual channels.  This article outlines the basics of DVCs and shows how to write a complete DVC application and client plug-in to add basic file transfer support to Terminal Services.

DVC Basics

What are Virtual Channels?

Virtual channels are bi-directional connection streams provided through the RDP protocol. Virtual channels allow third parties to establish a data pipe between the TS client and server to extend the functionality of the Remote Desktop Protocol (RDP). Examples of extra functionality provided through virtual channels are cross-TS-connection clipboard, drive, printer and smart card redirection. There are two types of virtual channels: static and dynamic. Due to the limitations of static virtual channels referenced above, dynamic virtual channels are the preferred way to extend TS functionality.

Client and Server DVC components

On the TS client side the DVC is handled through a TS client plug-in. This plug-in is a COM object, whose registered CLSID is passed to the TS client through the registry (see the attached sample). The COM object must implement the IWTSPlugininterface. On the server side any arbitrary component running in the current session can use the WTS API to establish the DVC connection, as well as send and receive data.

Channel Initialization and Usage

Client Side

1) The TS client loads the DVC plug-ins from the registry:

HKCU\Software\Microsoft\Terminal Server Client\Default\AddIns

2) The TS client invokes the Initialize() method on IWTSPlugin; and passes an IWTSVirtualChannelManager

HRESULT CTsClientPlgn::Initialize(

IWTSVirtualChannelManager *pChannelMgr

)

3) During initialization, or at any arbitrary point, the plug-in is expected to use the IWTSVirtualChannelManager to create a connection listener and pass an IWTSListenerCallback

hr = pChannelMgr->CreateListener(TSTELE_CHANNEL_NAME,

0,

pListenerCallback,

&pListener);

4) IWTSListenerCallback is notified of connection requests on the channel; IWTSListenerCallback receives anIWTSVirtualChannel for every new connection and returns a corresponding IWTSVirtualChannelCallback

HRESULT CTsListenerCallback::OnNewChannelConnection(

IWTSVirtualChannel *pChannel,

BSTR data,

BOOL *pbAccept,

IWTSVirtualChannelCallback **ppCallback )

{

*pbAccept = TRUE;

_pChannelCallback->AddRef();

*ppCallback = _pChannelCallback;

pChannel->AddRef();

_pChannel = pChannel;

5) The plug-in uses the IWTSVirtualChannel to write to and close the channel

hr = _pChannel->Write(sizeof(HRESULT), (PBYTE) &hr, NULL);

hr = _pChannel->Close();

6) The plug-in receives incoming data and channel close notifications on the IWTSVirtualChannelCallback

HRESULT CTsChannelCallback::OnDataReceived(

ULONG cbSize,

BYTE *pBuffer

);

HRESULT CTsChannelCallback::OnClose();

Server Side

1) An application issues a WTSVirtualChannelOpenEx with the WTS_CHANNEL_OPTION_DYNAMIC flag to establish the DVC connection.

hWTSHandle = WTSVirtualChannelOpenEx(

WTS_CURRENT_SESSION,

TSTELE_CHANNEL_NAME,

WTS_CHANNEL_OPTION_DYNAMIC);

2) Using the WTS handle received from the previous call a WTSVirtualChannelQuery is used to get a read/write file handle for the channel

NOTE: DuplicateHandle() is needed to be able to access the channel after freeing hWTSHandle (i.e. calling WTSVirtualChannelClose()). The output handle from DuplicateHandle() needs to be closed using CloseHandle().

BOOL bSucc = WTSVirtualChannelQuery(

hWTSHandle,

WTSVirtualFileHandle,

&vcFileHandlePtr,

&len);

...

HANDLE hWTSFileHandle = *(HANDLE *)vcFileHandlePtr;

...

bSucc = DuplicateHandle(

GetCurrentProcess(),

hWTSFileHandle,

GetCurrentProcess(),

&_hDVC,

0,

FALSE,

DUPLICATE_SAME_ACCESS);

3) Overlapped ReadFile() and WriteFile() calls are issued on the channel file handle

bRet = ReadFile(_hDVC, ReadBuf, CHANNEL_PDU_LENGTH, &BytesRead, &ovr);

bRet = WriteFile(_hDVC, pPacket, RequiredLen, &BytesWrit, &ovr);

4) To close the connection the channel file handle is closed

CloseHandle(_hDVC);

Sample: TS-Teleport

TS-Teleport is a sample application to demonstrate the end to end use of the DVC APIs. It implements a simple protocol to transport files from the TS server session to the desktop of the client machine. It does not rely on similar TS functionality like drive redirection.

The server component is a shell extension that adds an “RDP Client Desktop” entry to the “Send To” context menu. Upon receiving the list of highlighted files which the user elected to “Send to the RDP Client Desktop”, the shell extension opens the DVC and streams the files through. Upon receiving the file names and data, the client component creates those files and directories on the desktop.

The server sends a series of state dependent requests to the client by writing on the DVC and for each request it reads the status through a DVC read. Requests are start and end pairs for files and directories and data packets for file data.

Sample Files and Instructions

Please follow the link below to access sample files and instructions, including source code and installation how-to.

http://blogs.msdn.com/ts/pages/ts-teleport-sample-instructions.aspx

Dynamic Virtual Channels的更多相关文章

  1. PatentTips – GPU Saving and Restoring Thread Group Operating State

    BACKGROUND OF THE INVENTION The present invention relates generally to single-instruction, multiple- ...

  2. Satisfying memory ordering requirements between partial reads and non-snoop accesses

    A method and apparatus for preserving memory ordering in a cache coherent link based interconnect in ...

  3. Architectures for concurrent graphics processing operations

    BACKGROUND 1. Field The present invention generally relates to rendering two-dimension representatio ...

  4. Cross-Domain Security For Data Vault

    Cross-domain security for data vault is described. At least one database is accessible from a plural ...

  5. Massively parallel supercomputer

    A novel massively parallel supercomputer of hundreds of teraOPS-scale includes node architectures ba ...

  6. s5p6818 Overview

    S5P6818: 64bit Octa-Core, High Performance, Advanced 3D Graphics, Full-HD Multimedia Video, A53 Core ...

  7. HLS入门收集(1)

    使用HLS各种问题 关于求指数函数 exp(x) 在HLS中使用exp(x),也就是指数函数.不能导出RTL到EDK也就是Pcore  只能导出为VIVADO IP:相关解释:见官方论坛 http:/ ...

  8. C++的静态分发(CRTP)和动态分发(虚函数多态)的比较

    虚函数是C++实现多态的工具,在运行时根据虚表决定调用合适的函数.这被称作动态分发.虚函数很好的实现了多态的要求,但是在运行时引入了一些开销,包括: 对每一个虚函数的调用都需要额外的指针寻址 虚函数通 ...

  9. Down to the TLP: How PCI express devices talk (Part II)

    http://xillybus.com/tutorials/pci-express-tlp-pcie-primer-tutorial-guide-2 Data Link Layer Packets A ...

随机推荐

  1. Java 征途:行者的地图 (转)

    http://www.cnblogs.com/mindwind/p/5251430.html Java 征途:行者的地图   前段时间应因缘梳理了下自己的 Java 知识体系, 成文一篇望能帮到即将走 ...

  2. CSS 实现加载动画之二-圆环旋转

    上次简单的介绍了下如何用代码实现菊花旋转的加载动画,动画点击,这次继续我们的动画系列,实现另外一种加载动画,圆环旋转.与上次不同的是,菊花旋转是通过改变元素透明度来实现动画,这次因为考虑到元素叠加,加 ...

  3. 北京联想招聘-java 云服务开发工程师 加入qq 群:220486180 或者直接在此 留言咨询

     Position Title: 云服务开发工程师 Experience Required:  3 - 5 Years 负责联想企业网盘服务端开发  Position Requirements  1. ...

  4. 关于matlab中特殊字符, 上标和下标

    'T=25\circC',(摄氏度) 下标用 _{下划线} 上标用^ (尖号) 希腊字母等特殊字符用 α \alpha β \beta γ \gamma θ \theta Θ \Theta Г \Ga ...

  5. vector 内存释放问题

    关于容器的处理,只是拿来用,理解不深,但是今天跑程序出了问题.释放空间未得到真正的释放.于是网上找了一些文章,解决的问题. 解决方法:使用swap 加上clear,一起释放空间. 原理:即先创建一个临 ...

  6. Android WebView使用深入浅出

    目前很多android app都内置了可以显示web页面的界面,会发现这个界面一般都是由一个叫做WebView的组件渲染出来的,学习该组件可以为你的app开发提升扩展性. 先说下WebView的一些优 ...

  7. MFC实现Gif动画制作工具

    每天来博客园逛,看里面各种好文章,发现自己已经许久没有分享点什么了. 前几天用MFC设计了一个小型的Gif动画制作工具,思路如下: 1.支持图片格式:"*.jpg","* ...

  8. 在ubuntu server上安装沸腾时刻环境

    1. 安装php5.6 http://phpave.com/upgrade-to-php-56-on-ubuntu-1404-lts/ 按照这篇文章的顺序来做,可以安装最新5.6版本php 安装好了以 ...

  9. [BZOJ1211][HNOI2004]树的计数(Prufer序列)

    题目:http://www.lydsy.com:808/JudgeOnline/problem.php?id=1211 分析: 关于无根树的组合数学问题肯定想到Prufer序列,类似bzoj1005那 ...

  10. 序列化和反序列化的几种方式(JavaScriptSerializer 、XmlSerializer、DataContractSerializer)(一)

    JavaScriptSerializer 类 为启用 AJAX 的应用程序提供序列化和反序列化功能. 命名空间:   System.Web.Script.Serialization 程序集:  Sys ...