IPacket.ReadInt32-Methode
Aktualisiert: November 2007
Liest eine ganze Zahl aus dem Objekt und verweist den internen Iterator auf das nächste Datenobjekt im Paket.
Namespace: Microsoft.SmartDevice.DeviceAgentTransport
Assembly: Microsoft.SmartDevice.DeviceAgentTransport (in Microsoft.SmartDevice.DeviceAgentTransport.dll)
Syntax
Function ReadInt32 As Integer
Dim instance As IPacket
Dim returnValue As Integer
returnValue = instance.ReadInt32()
int ReadInt32()
int ReadInt32()
function ReadInt32() : int
Rückgabewert
Typ: System.Int32
Die aus dem Paket gelesene ganze Zahl.
Beispiele
' 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);
}
Berechtigungen
- Volle Vertrauenswürdigkeit für den unmittelbaren Aufrufer. Dieser Member kann von nur teilweise vertrauenswürdigem Code nicht verwendet werden. Weitere Informationen finden Sie unter Verwenden von Bibliotheken aus teilweise vertrauenswürdigem Code.