473,473 Members | 2,274 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to read from a file into a structure?

I am writing a class to wrap a RIFF file, so i have to read and decode some
structured data on the file.

For example, in the begining of file is a header:

Public Structure RiffHeader
Public id As Int32 ' (a FOURCC actually)
Public fileSize As Int32
Public fileType As Int32
End Structure

How can a I read from the file into a RiffHeader structure?

Regards, Alejandro Lapeyre
Nov 20 '05 #1
5 3315
Public Sub GetHeaderInfo(ByRef myHeader As RiffHeader)
Dim myFile As Integer
Dim i As Integer

myFile = FreeFile
Open "aFileName.riff" For Random Access Read _
As myFile Len = len(RiffHeader) // or is it sizeOf()?
Get myFile, 1, myHeader
Close myFile
End Sub
-----Original Message-----
I am writing a class to wrap a RIFF file, so i have to read and decode somestructured data on the file.

For example, in the begining of file is a header:

Public Structure RiffHeader
Public id As Int32 ' (a FOURCC actually)
Public fileSize As Int32
Public fileType As Int32
End Structure

How can a I read from the file into a RiffHeader structure?
Regards, Alejandro Lapeyre
.

Nov 20 '05 #2
* <an*******@discussions.microsoft.com> scripsit:
Public Sub GetHeaderInfo(ByRef myHeader As RiffHeader)
Dim myFile As Integer
Dim i As Integer

myFile = FreeFile
Open "aFileName.riff" For Random Access Read _
As myFile Len = len(RiffHeader) // or is it sizeOf()?
Get myFile, 1, myHeader
Close myFile
End Sub


That's VB6 code, isn't it? In VB.NET you will have to use 'FileOpen',
'FileGet', 'FileClose' and so on.

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>
Nov 20 '05 #3
Thank you for your time.
I am looking for the ".NET way" to do it. (no VB specifics libraries).

I am using IO.FileStream and it reads into a Bytes() as byte buffer. How can
i move this bytes into a structure?
Do I have to look in serialization?

Thank you, again. :-)

Regards,
Alejandro Lapeyre
Nov 20 '05 #4
Thanks for your time!

I was looking for a "standard .NET way" to do it.

Finaly, i have a working class using a FileStream and a BinaryReader, I fill
the structure using the BinaryReader.ReadInt32 and ReadChar methods.

Is there any other way to fill a structure from a some Bytes()?

Regards,
Alejandro Lapeyre
Nov 20 '05 #5
* "Alejandro Lapeyre" <no*********************@hotmail.com> scripsit:
I was looking for a "standard .NET way" to do it.

Finaly, i have a working class using a FileStream and a BinaryReader, I fill
the structure using the BinaryReader.ReadInt32 and ReadChar methods.

Is there any other way to fill a structure from a some Bytes()?


I don't think so. But why not use VB.NET's methods for doing that?

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>
Nov 20 '05 #6

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

Similar topics

3
by: Michael Van Altena via .NET 247 | last post by:
I'm trying to figure out how to read a formatted binary file intoa structure definition in C#. I've tried using the"StructLayout" attribute with both LayoutKind.Explicit andLayoutKind.Sequential...
5
by: Vasilis Serghi | last post by:
Hi all, I am fairly new to C programming and I have come to a stand still. I am trying to create a program that will accept a user input and give the user an output depending on the contents of a...
3
by: Dave Coate | last post by:
Hello again, I am going to re-post a question. I got some excellent suggestions from Rob and Mattias on this but their ideas did not solve the problem. Here is the original post: ...
2
by: Eric | last post by:
Hi, I need to send data from a file into a structure. In Vb6 this was done like so. public Type Struct1 v1 as string v2 as string end type
8
by: a | last post by:
I have a struct to write to a file struct _structA{ long x; int y; float z; } struct _structA A; //file open write(fd,A,sizeof(_structA)); //file close
0
by: brendon | last post by:
I need to read in a jpeg or bmp file in to memory and then save these files in to a resource file for distribution in a form other than jpeg or bmp. This requires only one file to be distributed, the...
11
by: waffle.horn | last post by:
Hi, if this makes sense i want to create a function that can be called so that it reads a single line from a file, then after using the information destroys it. Such that when the function is...
9
by: Hollywood | last post by:
Hello members of the comp.lang.c++, My log file is made of a set of 1000 following lines kind: 21/09/07 13:49:56,MW.SET.D_IGLS,2.000000 21/09/07 13:49:56,MW.SET.GNP_NT,7.000000 ..... ...
6
by: zl2k | last post by:
hi, there I have a appendable binary file of complex data structure named data.bin created by myself. It is written in the following format: number of Data, Data array Suppose I have...
0
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,...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
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...

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.