2014-03-01 09:32:23 +04:00
|
|
|
|
|
|
|
#include <winpr/crt.h>
|
|
|
|
#include <winpr/error.h>
|
|
|
|
#include <winpr/wtsapi.h>
|
|
|
|
|
2015-02-10 20:05:40 +03:00
|
|
|
int TestWtsApiExtraVirtualChannel(int argc, char* argv[])
|
2014-03-01 09:32:23 +04:00
|
|
|
{
|
|
|
|
BOOL bSuccess;
|
|
|
|
ULONG length;
|
|
|
|
ULONG bytesRead;
|
|
|
|
ULONG bytesWritten;
|
|
|
|
BYTE buffer[1024];
|
|
|
|
HANDLE hVirtualChannel;
|
|
|
|
|
|
|
|
length = sizeof(buffer);
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
hVirtualChannel =
|
|
|
|
WTSVirtualChannelOpen(WTS_CURRENT_SERVER_HANDLE, WTS_CURRENT_SESSION, "sample");
|
2014-03-01 09:32:23 +04:00
|
|
|
|
2015-02-10 20:05:40 +03:00
|
|
|
if (hVirtualChannel == INVALID_HANDLE_VALUE)
|
2014-03-01 09:32:23 +04:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
printf("WTSVirtualChannelOpen failed: %" PRIu32 "\n", GetLastError());
|
2015-02-10 20:05:40 +03:00
|
|
|
return -1;
|
2014-03-01 09:32:23 +04:00
|
|
|
}
|
2015-02-10 20:05:40 +03:00
|
|
|
printf("WTSVirtualChannelOpen opend");
|
2014-03-01 09:32:23 +04:00
|
|
|
bytesWritten = 0;
|
2019-11-06 17:24:51 +03:00
|
|
|
bSuccess = WTSVirtualChannelWrite(hVirtualChannel, (PCHAR)buffer, length, &bytesWritten);
|
2014-03-01 09:32:23 +04:00
|
|
|
|
|
|
|
if (!bSuccess)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
printf("WTSVirtualChannelWrite failed: %" PRIu32 "\n", GetLastError());
|
2015-02-10 20:05:40 +03:00
|
|
|
return -1;
|
2014-03-01 09:32:23 +04:00
|
|
|
}
|
2015-02-10 20:05:40 +03:00
|
|
|
printf("WTSVirtualChannelWrite written");
|
2014-03-01 09:32:23 +04:00
|
|
|
|
|
|
|
bytesRead = 0;
|
2019-11-06 17:24:51 +03:00
|
|
|
bSuccess = WTSVirtualChannelRead(hVirtualChannel, 5000, (PCHAR)buffer, length, &bytesRead);
|
2014-03-01 09:32:23 +04:00
|
|
|
|
|
|
|
if (!bSuccess)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
printf("WTSVirtualChannelRead failed: %" PRIu32 "\n", GetLastError());
|
2015-02-10 20:05:40 +03:00
|
|
|
return -1;
|
2014-03-01 09:32:23 +04:00
|
|
|
}
|
2015-02-10 20:05:40 +03:00
|
|
|
printf("WTSVirtualChannelRead read");
|
2014-03-01 09:32:23 +04:00
|
|
|
|
|
|
|
if (!WTSVirtualChannelClose(hVirtualChannel))
|
|
|
|
{
|
|
|
|
printf("WTSVirtualChannelClose failed\n");
|
2015-02-10 20:05:40 +03:00
|
|
|
return -1;
|
2014-03-01 09:32:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|