summaryrefslogtreecommitdiffstats
path: root/winpr/libwinpr/wtsapi/test/TestWtsApiExtraDynamicVirtualChannel.c
blob: d0bd87ed333333b2f9182d603208a29a97fce895 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <winpr/crt.h>
#include <winpr/error.h>
#include <winpr/wtsapi.h>

int TestWtsApiExtraDynamicVirtualChannel(int argc, char* argv[])
{
	BOOL bSuccess;
	ULONG length;
	ULONG bytesRead;
	ULONG bytesWritten;
	BYTE buffer[1024];
	HANDLE hVirtualChannel;

	length = sizeof(buffer);

	hVirtualChannel =
	    WTSVirtualChannelOpenEx(WTS_CURRENT_SESSION, "ECHO", WTS_CHANNEL_OPTION_DYNAMIC);

	if (hVirtualChannel == INVALID_HANDLE_VALUE)
	{
		printf("WTSVirtualChannelOpen failed: %" PRIu32 "\n", GetLastError());
		return -1;
	}
	printf("WTSVirtualChannelOpen opend");
	bytesWritten = 0;
	bSuccess = WTSVirtualChannelWrite(hVirtualChannel, (PCHAR)buffer, length, &bytesWritten);

	if (!bSuccess)
	{
		printf("WTSVirtualChannelWrite failed: %" PRIu32 "\n", GetLastError());
		return -1;
	}
	printf("WTSVirtualChannelWrite written");

	bytesRead = 0;
	bSuccess = WTSVirtualChannelRead(hVirtualChannel, 5000, (PCHAR)buffer, length, &bytesRead);

	if (!bSuccess)
	{
		printf("WTSVirtualChannelRead failed: %" PRIu32 "\n", GetLastError());
		return -1;
	}
	printf("WTSVirtualChannelRead read");

	if (!WTSVirtualChannelClose(hVirtualChannel))
	{
		printf("WTSVirtualChannelClose failed\n");
		return -1;
	}

	return 0;
}