A
amdrit
Hello Everyone,
I am having an issue using an API and was wondering if you could point out what I am doing wrong. The error that I am getting is 'The paramater is not correct.' I am unable to figure out what paramater the error is referring to.
The API Call is WTSVirtualChannelRead and below is the signature from MSDN.
Thanks in advance
//////////////////////////////////
// //
// BOOL WTSVirtualChannelRead( //
// HANDLE hChannelHandle, //
// ULONG TimeOut, //
// PCHAR Buffer, //
// ULONG BufferSize, //
// PULONG pBytesRead //
// ); //
// //
/////////////////////////////////
[DllImport("Wtsapi32.dll", SetLastError = true)]
private static extern bool WTSVirtualChannelRead(IntPtr handle,
int timeout,
ref byte[] buffer,
int readlength,
ref int bytesRead);
void buttonClick(..)
{
int intHandle =0;
byte[] bytes =new byte[0];
int bytesRead =0;
if(success = Win32.WtsApi32.WTSVirtualChannelQuery(
mHandle,
(int)1, //file handle
ref intHandle,
ref bytesRead
))
{
bytesRead=0;
IntPtr intHandlePtr=(IntPtr)intHandle;
//Wait for 5 seconds before timing out
//Channel Chunk size is 1600 bytes
if(!WTSVirtualChannelRead(intHandlePtr, (int)5000, ref bytes, (int)1600, ref bytesRead))
{
try
{ throw new Win32Exception(Marshal.GetLastWin32Error()); }
catch (Win32Exception e)
{ Console.WriteLine("Read Error:" + e.ToString()); }
}
else
{
Console.WriteLine("Success!");
}
}
}
I am having an issue using an API and was wondering if you could point out what I am doing wrong. The error that I am getting is 'The paramater is not correct.' I am unable to figure out what paramater the error is referring to.
The API Call is WTSVirtualChannelRead and below is the signature from MSDN.
Thanks in advance
//////////////////////////////////
// //
// BOOL WTSVirtualChannelRead( //
// HANDLE hChannelHandle, //
// ULONG TimeOut, //
// PCHAR Buffer, //
// ULONG BufferSize, //
// PULONG pBytesRead //
// ); //
// //
/////////////////////////////////
[DllImport("Wtsapi32.dll", SetLastError = true)]
private static extern bool WTSVirtualChannelRead(IntPtr handle,
int timeout,
ref byte[] buffer,
int readlength,
ref int bytesRead);
void buttonClick(..)
{
int intHandle =0;
byte[] bytes =new byte[0];
int bytesRead =0;
if(success = Win32.WtsApi32.WTSVirtualChannelQuery(
mHandle,
(int)1, //file handle
ref intHandle,
ref bytesRead
))
{
bytesRead=0;
IntPtr intHandlePtr=(IntPtr)intHandle;
//Wait for 5 seconds before timing out
//Channel Chunk size is 1600 bytes
if(!WTSVirtualChannelRead(intHandlePtr, (int)5000, ref bytes, (int)1600, ref bytesRead))
{
try
{ throw new Win32Exception(Marshal.GetLastWin32Error()); }
catch (Win32Exception e)
{ Console.WriteLine("Read Error:" + e.ToString()); }
}
else
{
Console.WriteLine("Success!");
}
}
}