Advertisement
Guest User

Untitled

a guest
Oct 21st, 2012
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.98 KB | None | 0 0
  1.         [StructLayout(LayoutKind.Sequential, Size = 16, Pack = 1)]
  2.         public struct ListEntry {
  3.             public byte version;
  4.             public UInt16 magic;
  5.             public UInt32 start_time;
  6.             public UInt16 run_id;
  7.             public UInt16 channels;
  8.             public UInt16 sampling_rate;
  9.             public UInt32 start_sector;
  10.         }
  11.  
  12.         public unsafe Form1() {
  13.             InitializeComponent();
  14.  
  15.             byte[] test = new byte[] { 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
  16.             fixed (byte* p = &test[0]) {
  17.                 //ListEntry list = (ListEntry)RawDataToObject(ref test, typeof(ListEntry));
  18.  
  19.                 ListEntry list = (ListEntry)Marshal.PtrToStructure((IntPtr)p, typeof(ListEntry));
  20.  
  21.                 listBox1.Items.Add(list.version);
  22.                 list.version = 3;
  23.                 listBox1.Items.Add("--");
  24.                 for (int i=0;i<16; i++)   listBox1.Items.Add(test[i]);
  25.             }
  26.  
  27.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement