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