'Imports System
'Imports System.Runtime.InteropServices
Private Function StructToByteArray(ByVal Struct As Object) As Byte()
Dim StructSize As Integer = Marshal.SizeOf(Struct)
Dim StructPrt As IntPtr = Marshal.AllocHGlobal(Marshal.SizeOf(Struct))
Dim StructBytes() As Byte = CType(Array.CreateInstance(GetType(Byte), StructSize), Byte())
Marshal.StructureToPtr(Struct, StructPrt, False)
Marshal.Copy(StructPrt, StructBytes, 0, StructSize)
Marshal.FreeHGlobal(StructPrt)
Return StructBytes
End Function