HighTechTalks DotNet Forums  

Copying Byte Array To Structure???

VB.net Upgrade microsoft.public.dotnet.languages.vb.upgrade


Discuss Copying Byte Array To Structure??? in the VB.net Upgrade forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Brian Black
 
Posts: n/a

Default 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

Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.