Well the issue is you are sending a 16bit unicode string in the sending side and reading out a ansi string on the other so the marshalling layer is terminating the string buffer at the first NUL character. You could either changing the UnmanagedType.LPStr
to UnmanagedType.LPWStr
or marshal it as a byte array and then convert to a string using a Unicode Encoding class.
Something like this might work (NOTE: untested code as I don't have a server to test on):
public static extern int WTSVirtualChannelRead(IntPtr hChannel,
uint Timeout,
[Out, MarshalAs(UnmanagedType.LPArray, SizeParamIndex=3)] byte[] Buffer,
uint BufferSize,
out uint BytesRead);
string DoRead(IntPtr hChannel)
{
byte[] buf = new byte[1024];
uint bytesRead;
if (WTSVirtualChannelRead(hChannel, 0, buf, (uint)buf.Length, out bytesRead) != 0)
{
return Encoding.Unicode.GetString(buf, 0, (int)bytesRead);
}
else
{
return "";
}
}
tyranid
2010-04-26 21:36:06