473,779 Members | 1,952 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

copying byte array to structure containg fix length arrays

Hi,
Sorry For the Cross Posting But, 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(N UM_OF_FUEL_TANK S - 1)> Dim FuelLevels() As Integer

Public Sub Initialize()
ReDim FuelLevels(NUM_ OF_FUEL_TANKS - 1)
End Sub
End Structure
Public Sub UnPackNewData(B yRef NewDataArray() As Byte)
Dim TempInputStruct As H_I_FuelStruct
Dim hGC As GCHandle
Dim pTempInputStruc t As IntPtr 'pointers to data array.

'TempInputStruc t.Initialize()

'Get the pointer to byte array
hGC = GCHandle.Alloc( NewDataArray, GCHandleType.Pi nned)
'assign the pointer
'pTempInputStru ct = Marshal.AllocHG lobal(len(TempI nputStruct))
pTempInputStruc t = hGC.AddrOfPinne dObject

'This is where shit stops working''''''

'I want to have the data at the pointer copied into the
'TempInputStruc t.

'Copy the memory from the byte array to our tempstruct.
'Marshal.PtrToS tructure(pTempI nputStruct, New H_I_FuelStruct( ).GetType)

TempInputStruct = CType(Marshal.P trToStructure(p TempInputStruct ,
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
Nov 21 '05 #1
0 1827

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
437
by: Steve Mauldin | last post by:
I came across an example in the MSDN documentation using RC2 encryption(the link to the article is at the end of this message). When I tried it I had a problem with getting back the same length string that I sent into it. After working on Debugging the code I found two problems. One was in the statement fromEncrypt = New Byte(encrypted.Length) {} where both FromEncrypt and encrypted are both byte arrays and encrypted's length is 24....
6
2167
by: Max Metral | last post by:
I have a "high performance" application I'm building in C#. I have a preparation program that builds a large file that is layed out "properly" with indexes etc. So my goal is to read that file into a big byte array, and pass offsets around to various functions and classes. My structure is something like: int Id; int numItems; byte foo; int fooIds;
2
10363
by: Shreddy | last post by:
Hi, I'm trying (or struggling) to convert some C code to C#. The existing C client is sending a structure via a TCP socket to a network server. The structure contains a mix of int and char data types . I can re-create the structure in c# with LayoutKind.Explicit, but how do I convert this structure to a byte array for use with the Socket.Send() method?
8
4592
by: frekster | last post by:
Hi. I used to be able to do this easily in vb 6 via looping and preserving the source array data/size etc. How can I do this in vb.net? I've been trying for a while now and this should be an easy task but it just isn't clicking. For some reason, the preserve doesn't seem to be working.
6
4682
by: Vitaly Zayko | last post by:
It's probably simple but I can't find a way how to copy number of bytes from one byte array to another? Just like Array.Copy(SourceArray, SourceIndex, DestArray, DestIndex, Length) does but in my case the arrays have different length. Of course I can copy byte by byte but I guess there should be a function for such task. Thanks! -- Vit Zayko
17
7255
by: =?Utf-8?B?U2hhcm9u?= | last post by:
Hi Gurus, I need to transfer a jagged array of byte by reference to unmanaged function, The unmanaged code should changed the values of the array, and when the unmanaged function returns I need to show the array data to the end user. Can I do that? How?
4
1018
by: Jerry Spence1 | last post by:
I have one array which is base 1 (rather than 0) and I am trying to use array.copy to copy it into a new array. I get the error: Unable to cast object of type 'System.Byte' to type 'System.Byte'. I think this is because the new array, by default is base 0. Without creating a wasteful loop and handling byte for byte, how can I create a base 0 array from a base 1 array? -Jerry
10
6382
by: Scott Townsend | last post by:
So I need to talk to a devices that expects all of the bits and bytes I sent it to be in specific places (not yet 100% defined). I wanted to create a structure/class with all of the data in it and then convert that to a byte array, pass it to the device, then get a reply and then convert that to a structure. I'm having issues with making sure what I've coded is correct. Cant figure out how to define an array in structure that is a...
2
7207
by: O.B. | last post by:
When using Marshal to copy data from a byte array to the structure below, only the first byte of the "other" array is getting copied from the original byte array. What do I need to specify to get Marshal.PtrToStructure to copy the all the data into the "other" array? unsafe public struct DeadReckoning {
0
9636
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10306
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10074
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8961
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7485
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5373
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4037
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3632
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2869
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.