Put some bytes into a structure?

  • Thread starter Thread starter Dan
  • Start date Start date
D

Dan

Is there a way to place x number of bytes directly into a
structure? Specifically with this structure:

Private Structure HeaderVersion1
Dim intVersion As Int16
Dim intCount As Int16
Dim intSysUptime As Int32
Dim intUnix_Secs As Int32
Dim intUnix_nsecs As Int32
End Structure

Is there an efficient way to read the first 16 bytes from
a byte array into the structure so that the first 2 bytes
= intVersion, the second 2 = int Count, the next 4 =
intSysUptime, etc. Thanks for your input.

Dan
 
Is there a way to place x number of bytes directly into a
structure?

Use some bytes shifting and/or masking with AND, >>, << operators.
Read
http://msdn.microsoft.com/library/e...vbconvisualbasicnet2003languagechangesanchor6
article on MSDN, read "Breaking Apart a Multipart Value" part.

sincerely,
--
Sebastian Zaklada
Skilled Software
http://www.skilledsoftware.com
************************************
SQL Source Control 2003 - for
SQL Server Source Safe integration
and custom databases documentation
 
* "Dan said:
Is there a way to place x number of bytes directly into a
structure? Specifically with this structure:

Private Structure HeaderVersion1
Dim intVersion As Int16
Dim intCount As Int16
Dim intSysUptime As Int32
Dim intUnix_Secs As Int32
Dim intUnix_nsecs As Int32
End Structure

Is there an efficient way to read the first 16 bytes from
a byte array into the structure so that the first 2 bytes
= intVersion, the second 2 = int Count, the next 4 =
intSysUptime, etc. Thanks for your input.

If you have a pointer to the data, you can use
'System.Runtime.InteropServices.Marshal.PtrToStructure'.
 
Back
Top