FreeRDP
TestWtsApiExtraDynamicVirtualChannel.c
1 
2 #include <winpr/crt.h>
3 #include <winpr/error.h>
4 #include <winpr/wtsapi.h>
5 
6 int TestWtsApiExtraDynamicVirtualChannel(int argc, char* argv[])
7 {
8  WINPR_UNUSED(argc);
9  WINPR_UNUSED(argv);
10 
11  HANDLE hVirtualChannel =
12  WTSVirtualChannelOpenEx(WTS_CURRENT_SESSION, "ECHO", WTS_CHANNEL_OPTION_DYNAMIC);
13 
14  if (hVirtualChannel == INVALID_HANDLE_VALUE)
15  {
16  printf("WTSVirtualChannelOpen failed: %" PRIu32 "\n", GetLastError());
17  return -1;
18  }
19  printf("WTSVirtualChannelOpen opend");
20  ULONG bytesWritten = 0;
21  char buffer[1024] = { 0 };
22  size_t length = sizeof(buffer);
23  BOOL bSuccess = WTSVirtualChannelWrite(hVirtualChannel, buffer, length, &bytesWritten);
24 
25  if (!bSuccess)
26  {
27  printf("WTSVirtualChannelWrite failed: %" PRIu32 "\n", GetLastError());
28  return -1;
29  }
30  printf("WTSVirtualChannelWrite written");
31 
32  ULONG bytesRead = 0;
33  bSuccess = WTSVirtualChannelRead(hVirtualChannel, 5000, (PCHAR)buffer, length, &bytesRead);
34 
35  if (!bSuccess)
36  {
37  printf("WTSVirtualChannelRead failed: %" PRIu32 "\n", GetLastError());
38  return -1;
39  }
40  printf("WTSVirtualChannelRead read");
41 
42  if (!WTSVirtualChannelClose(hVirtualChannel))
43  {
44  printf("WTSVirtualChannelClose failed\n");
45  return -1;
46  }
47 
48  return 0;
49 }