Copying Byte Array To Structure??? -
01-13-2005
, 11:28 AM
Hi,
I just started programming .net and i have a question. I have a byte
array of 14 bytes (CODE BELOW), i need to copy the data from the the
byte array into the
Public Structure H_I_FuelStruct
Dim Tag As Short 'Tag 101
Dim Size As Short
<VBFixedArray(NUM_OF_FUEL_TANKS - 1)> Dim FuelLevels() As Integer
Public Sub Initialize()
ReDim FuelLevels(NUM_OF_FUEL_TANKS - 1)
End Sub
End Structure
Public Sub UnPackNewData(ByRef NewDataArray() As Byte)
Dim TempInputStruct As H_I_FuelStruct
Dim hGC As GCHandle
Dim pTempInputStruct As IntPtr 'pointers to data array.
'TempInputStruct.Initialize()
'Get the pointer to byte array
hGC = GCHandle.Alloc(NewDataArray, GCHandleType.Pinned)
'assign the pointer
'pTempInputStruct = Marshal.AllocHGlobal(len(TempInputStruct))
pTempInputStruct = hGC.AddrOfPinnedObject
'This is where shit stops working''''''
'I want to have the data at the pointer copied into the
'TempInputStruct.
'Copy the memory from the byte array to our tempstruct.
'Marshal.PtrToStructure(pTempInputStruct, New H_I_FuelStruct().GetType)
TempInputStruct = CType(Marshal.PtrToStructure(pTempInputStruct,
TempInputStruct), H_I_FuelStruct)
.......
The only data that gets copied into the Tempinput struct is all the
values except the fuel level array which is set to nothing?
i need to be able to copy data from an array into a structure and any
possible elements that may be an array be filled in. IS this possible |