Imports System.Runtime.InteropServices.Marshal
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim x As Integer
Dim y() As Byte
ReDim y(3)
x = 23456
Copy(x, y, 0, 4)
End Sub
End Class
public static void Copy(IntPtr source, byte[ ] destination, int startIndex, int length)
Member of System.Runtime.InteropServices.Marshal
Private Structure httpHeader
Dim Block1 As Integer
Dim Block2 As Integer
Dim Block3 As Integer
End Structure
Это как??Sebas писал(а):Если тебе нужно в бит() для передачи, то просто сериализуй её...
public class MyObject {
public int n1 = 0;
public int n2 = 0;
public String str = null;
}
The code example below shows how an instance of this class can be serialized to a file.
MyObject obj = new MyObject();
obj.n1 = 1;
obj.n2 = 24;
obj.str = "Some String";
IFormatter formatter = new BinaryFormatter();
Stream stream = new FileStream("MyFile.bin", FileMode.Create, FileAccess.Write, FileShare.None);
formatter.Serialize(stream, obj);
stream.Close();
Restoring the object back to its former state is just as easy. First, create a stream for reading and a formatter, and then instruct the formatter to deserialize the object. The code example below shows how this is done.
IFormatter formatter = new BinaryFormatter();
Stream stream = new FileStream("MyFile.bin", FileMode.Open, FileAccess.Read, FileShare.Read);
MyObject obj = (MyObject) formatter.Deserialize(stream);
stream.Close();
// Here's the proof.
Console.WriteLine("n1: {0}", obj.n1);
Console.WriteLine("n2: {0}", obj.n2);
Console.WriteLine("str: {0}", obj.str);
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim x As Integer
Dim i As IntPtr
Dim y() As Byte
ReDim y(3)
i = AllocCoTaskMem(4)
x = 23456
WriteInt32(i, 0, x)
Copy(i, y, 0, 4)
End Sub
End Class
Antonariy писал(а):В общем, все не то. Вот правильный ответ:
Imports System.Runtime.InteropServices.Marshal
- Код: Выделить всё
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim x As Integer
Dim i As IntPtr
Dim y() As Byte
ReDim y(3)
i = AllocCoTaskMem(4)
x = 23456
WriteInt32(i, 0, x)
Copy(i, y, 0, 4)
End Sub
End Class
Всем спасибо.
Сейчас этот форум просматривают: нет зарегистрированных пользователей и гости: 44