CChannel.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  1. /****************************************************************************/
  2. /* Header: cchannel.h */
  3. /* */
  4. /* Purpose: Virtual Channel Client API */
  5. /* */
  6. /* Copyright(C) Microsoft Corporation 1999 */
  7. /* */
  8. /****************************************************************************/
  9. #ifndef H_CCHANNEL
  10. #define H_CCHANNEL
  11. /****************************************************************************/
  12. /* Include Virtual Channel Protocol header */
  13. /****************************************************************************/
  14. #include <pchannel.h>
  15. #ifdef _WIN32
  16. #define VCAPITYPE _stdcall
  17. #define VCEXPORT
  18. #else // _WIN32
  19. #define VCAPITYPE CALLBACK
  20. #define VCEXPORT __export
  21. #endif // _WIN32
  22. /****************************************************************************/
  23. /* Name: CHANNEL_INIT_EVENT_FN */
  24. /* */
  25. /* Purpose: */
  26. /* */
  27. /* This function is passed to MSTSC on VirtualChannelInit. It is called by */
  28. /* MSTSC to tell the application about interesting events. */
  29. /* */
  30. /* Returns: */
  31. /* */
  32. /* none */
  33. /* */
  34. /* Params: */
  35. /* */
  36. /* - pInitHandle - a handle uniquely identifying this connection */
  37. /* - event - the event that has occurred - see CHANNEL_EVENT_XXX below */
  38. /* - pData - data associated with the event - see CHANNEL_EVENT_XXX below */
  39. /* - dataLength - length of the data. */
  40. /* */
  41. /****************************************************************************/
  42. typedef VOID VCAPITYPE CHANNEL_INIT_EVENT_FN(LPVOID pInitHandle,
  43. UINT event,
  44. LPVOID pData,
  45. UINT dataLength);
  46. typedef CHANNEL_INIT_EVENT_FN FAR * PCHANNEL_INIT_EVENT_FN;
  47. /****************************************************************************/
  48. /* Events passed to VirtualChannelInitEvent */
  49. /****************************************************************************/
  50. /* Client initialized (no data) */
  51. #define CHANNEL_EVENT_INITIALIZED 0
  52. /* Connection established (data = name of Server) */
  53. #define CHANNEL_EVENT_CONNECTED 1
  54. /* Connection established with old Server, so no channel support */
  55. #define CHANNEL_EVENT_V1_CONNECTED 2
  56. /* Connection ended (no data) */
  57. #define CHANNEL_EVENT_DISCONNECTED 3
  58. /* Client terminated (no data) */
  59. #define CHANNEL_EVENT_TERMINATED 4
  60. /****************************************************************************/
  61. /* Name: CHANNEL_OPEN_EVENT_FN */
  62. /* */
  63. /* Purpose: */
  64. /* */
  65. /* This function is passed to MSTSC on VirtualChannelOpen. It is called by */
  66. /* MSTSC when data is available on the channel. */
  67. /* */
  68. /* Returns: */
  69. /* */
  70. /* none */
  71. /* */
  72. /* Params: */
  73. /* */
  74. /* - openHandle - a handle uniquely identifying this channel */
  75. /* - event - event that has occurred - see CHANNEL_EVENT_XXX below */
  76. /* - pData - data received */
  77. /* - dataLength - length of the data */
  78. /* - totalLength - total length of data written by the Server */
  79. /* - dataFlags - flags, zero, one or more of: */
  80. /* - 0x01 - beginning of data from a single write operation at the Server */
  81. /* - 0x02 - end of data from a single write operation at the Server. */
  82. /* */
  83. /****************************************************************************/
  84. typedef VOID VCAPITYPE CHANNEL_OPEN_EVENT_FN(DWORD openHandle,
  85. UINT event,
  86. LPVOID pData,
  87. UINT32 dataLength,
  88. UINT32 totalLength,
  89. UINT32 dataFlags);
  90. typedef CHANNEL_OPEN_EVENT_FN FAR * PCHANNEL_OPEN_EVENT_FN;
  91. /****************************************************************************/
  92. /* Events passed to VirtualChannelOpenEvent */
  93. /****************************************************************************/
  94. /* Data received from Server (data = incoming data) */
  95. #define CHANNEL_EVENT_DATA_RECEIVED 10
  96. /* VirtualChannelWrite completed (pData - pUserData passed on
  97. VirtualChannelWrite) */
  98. #define CHANNEL_EVENT_WRITE_COMPLETE 11
  99. /* VirtualChannelWrite cancelled (pData - pUserData passed on
  100. VirtualChannelWrite) */
  101. #define CHANNEL_EVENT_WRITE_CANCELLED 12
  102. /****************************************************************************/
  103. /* Return codes from VirtualChannelXxx functions */
  104. /****************************************************************************/
  105. #define CHANNEL_RC_OK 0
  106. #define CHANNEL_RC_ALREADY_INITIALIZED 1
  107. #define CHANNEL_RC_NOT_INITIALIZED 2
  108. #define CHANNEL_RC_ALREADY_CONNECTED 3
  109. #define CHANNEL_RC_NOT_CONNECTED 4
  110. #define CHANNEL_RC_TOO_MANY_CHANNELS 5
  111. #define CHANNEL_RC_BAD_CHANNEL 6
  112. #define CHANNEL_RC_BAD_CHANNEL_HANDLE 7
  113. #define CHANNEL_RC_NO_BUFFER 8
  114. #define CHANNEL_RC_BAD_INIT_HANDLE 9
  115. #define CHANNEL_RC_NOT_OPEN 10
  116. #define CHANNEL_RC_BAD_PROC 11
  117. #define CHANNEL_RC_NO_MEMORY 12
  118. #define CHANNEL_RC_UNKNOWN_CHANNEL_NAME 13
  119. #define CHANNEL_RC_ALREADY_OPEN 14
  120. #define CHANNEL_RC_NOT_IN_VIRTUALCHANNELENTRY 15
  121. #define CHANNEL_RC_NULL_DATA 16
  122. #define CHANNEL_RC_ZERO_LENGTH 17
  123. /****************************************************************************/
  124. /* Levels of Virtual Channel Support */
  125. /****************************************************************************/
  126. #define VIRTUAL_CHANNEL_VERSION_WIN2000 1
  127. #ifdef __cplusplus
  128. extern "C" {
  129. #endif /* __cplusplus */
  130. /****************************************************************************/
  131. /* Name: VirtualChannelInit */
  132. /* */
  133. /* Purpose: */
  134. /* */
  135. /* This function is called by the application to register the virtual */
  136. /* channels it wants to have access to. Note that this does not open the */
  137. /* channels, merely reserves the names for use by this application. This */
  138. /* function must be called before the Client connects to the Server, hence */
  139. /* it is recommended that it is called from the DLL's initialization */
  140. /* procedure. */
  141. /* */
  142. /* */
  143. /* On_return, the channels requested have been registered. However, other */
  144. /* MSTSC initialization may not yet have completed. The application */
  145. /* receives a VirtualChannelInitEvent callback with the "Client */
  146. /* initialized" event when all MSTSC initialization is complete. */
  147. /* */
  148. /* Returns: */
  149. /* */
  150. /* CHANNEL_RC_OK */
  151. /* CHANNEL_RC_ALREADY_INITIALIZED */
  152. /* CHANNEL_RC_ALREADY_CONNECTED */
  153. /* CHANNEL_RC_TOO_MANY_CHANNELS */
  154. /* CHANNEL_RC_NOT_IN_VIRTUALCHANNELENTRY */
  155. /* */
  156. /* Parameters */
  157. /* */
  158. /* - ppInitHandle (returned) - handle to pass to subsequent */
  159. /* VirtualChannelXxx calls */
  160. /* - pChannel - list of names registered by this application */
  161. /* - channelCount - number of channels registered. */
  162. /* - versionRequested - level of virtual channel support requested (one of */
  163. /* the VIRTUAL_CHANNEL_LEVEL_XXX parameters) */
  164. /* - pChannelInitEventProc - address of VirtualChannelInitEvent procedure */
  165. /* */
  166. /****************************************************************************/
  167. typedef UINT VCAPITYPE VIRTUALCHANNELINIT(
  168. LPVOID FAR * ppInitHandle,
  169. PCHANNEL_DEF pChannel,
  170. INT channelCount,
  171. ULONG versionRequested,
  172. PCHANNEL_INIT_EVENT_FN pChannelInitEventProc);
  173. typedef VIRTUALCHANNELINIT FAR * PVIRTUALCHANNELINIT;
  174. /****************************************************************************/
  175. /* Name: VirtualChannelOpen */
  176. /* */
  177. /* Purpose: */
  178. /* */
  179. /* This function is called by the application to open a channel. It cannot */
  180. /* be called until a connection is established with a Server. */
  181. /* */
  182. /* Returns: */
  183. /* */
  184. /* CHANNEL_RC_OK */
  185. /* CHANNEL_RC_NOT_INITIALIZED */
  186. /* CHANNEL_RC_NOT_CONNECTED */
  187. /* CHANNEL_RC_BAD_CHANNEL_NAME */
  188. /* CHANNEL_RC_BAD_INIT_HANDLE */
  189. /* */
  190. /* Params: */
  191. /* */
  192. /* - pInitHandle - handle from VirtualChannelInit */
  193. /* */
  194. /* - pOpenHandle (returned) - handle to pass to subsequent */
  195. /* VirtualChannelXxx calls */
  196. /* - pChannelName - name of channel to open */
  197. /* - pChannelOpenEventProc - address of VirtualChannelOpenEvent procedure */
  198. /* */
  199. /****************************************************************************/
  200. typedef UINT VCAPITYPE VIRTUALCHANNELOPEN(
  201. LPVOID pInitHandle,
  202. LPDWORD pOpenHandle,
  203. PCHAR pChannelName,
  204. PCHANNEL_OPEN_EVENT_FN pChannelOpenEventProc);
  205. typedef VIRTUALCHANNELOPEN FAR * PVIRTUALCHANNELOPEN;
  206. /****************************************************************************/
  207. /* Name: VirtualChannelClose */
  208. /* */
  209. /* Purpose: */
  210. /* */
  211. /* This function is called to close a previously opened channel. */
  212. /* */
  213. /* Returns: */
  214. /* */
  215. /* CHANNEL_RC_OK */
  216. /* CHANNEL_RC_BAD_CHANNEL_HANDLE */
  217. /* */
  218. /* Params: */
  219. /* */
  220. /* - openHandle - handle returned on VirtualChannelOpen */
  221. /* */
  222. /****************************************************************************/
  223. typedef UINT VCAPITYPE VIRTUALCHANNELCLOSE(DWORD openHandle);
  224. typedef VIRTUALCHANNELCLOSE FAR * PVIRTUALCHANNELCLOSE;
  225. /****************************************************************************/
  226. /* Name: VirtualChannelWrite */
  227. /* */
  228. /* Purpose: */
  229. /* */
  230. /* This function is used to send data to the partner app on the Server. */
  231. /* */
  232. /* VirtualChannelWrite copies the data to one or more network buffers as */
  233. /* necessary. VirtualChannelWrite ensures that data is sent to the Server */
  234. /* on the right context. It sends all data on MS TC's Sender thread. */
  235. /* */
  236. /* VirtualChannelWrite is asynchronous - the VirtualChannelOpenEvent */
  237. /* procedure is called when the write completes. Until that callback is */
  238. /* made, the caller must not free or reuse the buffer passed on */
  239. /* VirtualChannelWrite. The caller passes a piece of data (pUserData) to */
  240. /* VirtualChannelWrite, which is returned on the VirtualChannelOpenEvent */
  241. /* callback. The caller can use this data to identify the write which has */
  242. /* completed. */
  243. /* */
  244. /* */
  245. /* Returns: */
  246. /* */
  247. /* CHANNEL_RC_OK */
  248. /* CHANNEL_RC_NOT_INITIALIZED */
  249. /* CHANNEL_RC_NOT_CONNECTED */
  250. /* CHANNEL_RC_BAD_CHANNEL_HANDLE */
  251. /* */
  252. /* Params: */
  253. /* - openHandle - handle from VirtualChannelOpen */
  254. /* - pData - data to write */
  255. /* - datalength - length of data to write */
  256. /* - pUserData - user supplied data, returned on VirtualChannelOpenEvent */
  257. /* when the write completes */
  258. /* */
  259. /****************************************************************************/
  260. typedef UINT VCAPITYPE VIRTUALCHANNELWRITE(DWORD openHandle,
  261. LPVOID pData,
  262. ULONG dataLength,
  263. LPVOID pUserData);
  264. typedef VIRTUALCHANNELWRITE FAR * PVIRTUALCHANNELWRITE;
  265. /****************************************************************************/
  266. /* Structure: CHANNEL_ENTRY_POINTS */
  267. /* */
  268. /* Description: Virtual Channel entry points passed to VirtualChannelEntry */
  269. /****************************************************************************/
  270. typedef struct tagCHANNEL_ENTRY_POINTS
  271. {
  272. DWORD cbSize;
  273. DWORD protocolVersion;
  274. PVIRTUALCHANNELINIT pVirtualChannelInit;
  275. PVIRTUALCHANNELOPEN pVirtualChannelOpen;
  276. PVIRTUALCHANNELCLOSE pVirtualChannelClose;
  277. PVIRTUALCHANNELWRITE pVirtualChannelWrite;
  278. } CHANNEL_ENTRY_POINTS, FAR * PCHANNEL_ENTRY_POINTS;
  279. /****************************************************************************/
  280. /* Name: VirtualChannelEntry */
  281. /* */
  282. /* Purpose: */
  283. /* */
  284. /* This function is provided by addin DLLS. It is called by MSTSC at */
  285. /* initialization to tell the addin DLL the addresses of the */
  286. /* VirtualChannelXxx functions. */
  287. /* */
  288. /* Returns: */
  289. /* */
  290. /* TRUE - everything OK */
  291. /* FALSE - error, unload the DLL */
  292. /* */
  293. /* Parameters: */
  294. /* */
  295. /* - pVirtualChannelInit - pointers to VirtualChannelXxx functions */
  296. /* - pVirtualChannelOpen */
  297. /* - pVirtualChannelClose */
  298. /* - pVirtualChannelWrite */
  299. /* */
  300. /****************************************************************************/
  301. typedef BOOL VCAPITYPE VIRTUALCHANNELENTRY(
  302. PCHANNEL_ENTRY_POINTS pEntryPoints);
  303. typedef VIRTUALCHANNELENTRY FAR * PVIRTUALCHANNELENTRY;
  304. #ifdef __cplusplus
  305. }
  306. #endif /* __cplusplus */
  307. #endif /* H_CCHANNEL */