IPacket.ReadString Method
Reads a string from the object and points the internal iterator to the next data object in the packet.
Namespace: Microsoft.SmartDevice.DeviceAgentTransport
Assembly: Microsoft.SmartDevice.DeviceAgentTransport (in Microsoft.SmartDevice.DeviceAgentTransport.dll)
Syntax
'Declaration
Function ReadString As String
'Usage
Dim instance As IPacket
Dim returnValue As String
returnValue = instance.ReadString()
string ReadString()
String^ ReadString()
function ReadString() : String
Return Value
Type: System.String
The string read from the packet.
Examples
' Check for a packet while communication stream is connected.
While packetStream.IsConnected()
' If a packet is found, display the string and integer data.
If packetStream.IsPacketAvailable() Then
packetStream.Read(packet)
Dim sb As New StringBuilder()
While Not packet.IsEndOfPacket()
Select Case packet.ReadDataType()
Case DataType.BoolType
Dim boolValue As Boolean = packet.ReadBool()
Case DataType.ByteArrayType
' Read bytes and convert IntPtr to byte[]
Dim ptr As IntPtr
Dim size As System.UInt32 = 0
packet.ReadBytes(ptr, size)
Dim buffer As Byte() = InteropUtils.ConvertIntPtrToByteArray(ptr, _
Convert.ToInt32(size))
Case DataType.ByteType
Dim byteValue As Byte = packet.ReadByte()
Case DataType.CharType
Dim charValue As Char = packet.ReadChar()
Case DataType.Int32Type
sb.Append("Int32Type: " + packet.ReadInt32().ToString() + _
vbCr + vbLf)
Case DataType.StringType
sb.Append("String: " + packet.ReadString() + vbCr + vbLf)
Case Else
End Select
End While
MessageBox.Show(sb.ToString())
Exit While
End If
System.Threading.Thread.Sleep(1000)
End While
// Check for a packet while communication stream is connected.
while (packetStream.IsConnected())
{
// If a packet is found, display the string and integer data.
if (packetStream.IsPacketAvailable())
{
packetStream.Read(out packet);
StringBuilder sb = new StringBuilder();
while (!packet.IsEndOfPacket())
{
switch (packet.ReadDataType())
{
case DataType.BoolType:
bool boolValue = packet.ReadBool();
break;
case DataType.ByteArrayType:
// Read bytes and convert IntPtr to byte[]
IntPtr ptr;
uint size = 0;
packet.ReadBytes(out ptr, out size);
byte[] buffer = InteropUtils.ConvertIntPtrToByteArray(ptr,
Convert.ToInt32(size));
break;
case DataType.ByteType:
byte byteValue = packet.ReadByte();
break;
case DataType.CharType:
char charValue = packet.ReadChar();
break;
case DataType.Int32Type:
sb.Append("Int32Type: " + packet.ReadInt32().ToString() + "\r\n");
break;
case DataType.StringType:
sb.Append("String: " + packet.ReadString() + "\r\n");
break;
default:
break;
}
}
MessageBox.Show(sb.ToString());
break;
}
System.Threading.Thread.Sleep(1000);
}
.NET Framework Security
- Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see Using Libraries from Partially Trusted Code.