473,385 Members | 1,521 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Reading into a structure.

I guess I am simply blind this morning. I have a binary file I want to read into a predefined structure of ints/strings/shorts and arrays. How do I go about this. In C++ I would simply define a type and read into it. All I can find now is strings, chars and bytes.
Nov 16 '05 #1
3 1592
You can still create a structure and read data into it, object-wise. I'm
often using this approach.
C# can also serialize an object (for instance a structure) and write/read
directly, but the performance is extremely low and memory and disk consuming
(but its VERY easy).

/Morten Nielsen
http://www.iter.dk

"BobTheHacker" <an*******@discussions.microsoft.com> wrote in message
news:2D**********************************@microsof t.com...
I guess I am simply blind this morning. I have a binary file I want to

read into a predefined structure of ints/strings/shorts and arrays. How do
I go about this. In C++ I would simply define a type and read into it. All
I can find now is strings, chars and bytes.
Nov 16 '05 #2
> I have tried type casting back, but must just be missing something. Must
be the Cold Medicine Kickiing in!

Don't type-cast your structure, but type-cast the elements in the structure
instead.
If that is what you want, you need to make your structure serializable and
use the deserializer to read the data (there is a nice example in the SDK).
But I don't think you can deserialize a structure that has been written to a
file from C++.

/Morten
Nov 16 '05 #3
I have stumbled in the formatter stuff and it mentions serialize/deserialize

What is the name of the Example. I haven't hit it yet. Below is the cut of my Structure. The file is in Binary format. This all seems to be a weak spot in MSDN. I must just be hitting all around it. I've tried this and get errors

System.Runtime.Serialization.Formatters.Binary.Bin aryFormatter bFormatter = new System.Runtime.Serialization.Formatters.Binary.Bin aryFormatter()

tr

V2Style sV2Style = (V2Style)bFormatter.Deserialize(fs)

catch(Exception f

MessageBox.Show(f.Message.ToString())
[ StructLayout(LayoutKind.Sequential, CharSet=CharSet.Auto)
public struct V2Styl

[ MarshalAs(UnmanagedType.ByValTStr, SizeConst=33) ] public string szTagname
[ MarshalAs(UnmanagedType.ByValTStr, SizeConst=33) ] public string pTagContext
public short font
public short emphasis
public short background
public short foreground
public short size
public short LineSpace
public short SpaceAbove
public short SpaceBelow
public short IndentLeft
public short IndentRight
public short IndentFirst
[ MarshalAs(UnmanagedType.ByValArray, SizeConst=10) ] public short tabsArray
public short justification
public ushort Flags
[ MarshalAs(UnmanagedType.ByValTStr, SizeConst=82) ] public string AttributeList
[ MarshalAs(UnmanagedType.ByValTStr, SizeConst=32) ] public string facename
public uint RGBfore; /* Foreground text color - version 2.0 *
public uint RGBback; /* Background text color - version 2.0 *
public byte BorderStyle
[ MarshalAs(UnmanagedType.ByValTStr, SizeConst=5) ] public string extra

Nov 16 '05 #4

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

Similar topics

7
by: Santah | last post by:
hi I'm new to C++ and I'm currently working on Visual C++ 6.0 I'm trying to open a text file, and read some data from it part of the text file looks like this: --------
20
by: ishmael4 | last post by:
hello everyone! i have a problem with reading from binary file. i was googling and searching, but i just cant understand, why isnt this code working. i could use any help. here's the source code:...
3
by: Zahid | last post by:
Hi, I have declared an array holding a custom declared structure. The structure looks like this: Private Structure MnuDataFrmFile Public menuGroup As String Public ItemDesc As String Public...
1
by: Roob | last post by:
I am learning C# and was wandering if there is a straightforward way to read a binary file created by C++. For example, I have a data structure as follows: typedef struct _data time_t date;...
3
by: Zeke Zinzul | last post by:
Hi Guys & Geeks, What's the most elegant way of dealing with binary data and structures? Say I have this (which I actually do, a woo-hoo): struct Struct_IconHeader { byte width; byte...
6
by: arne.muller | last post by:
Hello, I've come across some problems reading strucutres from binary files. Basically I've some strutures typedef struct { int i; double x; int n; double *mz;
16
by: Jm.GlezdeRueda | last post by:
Hi all, Im trying to read a 24bit bmp with fread, and i have some problems.. I want to read the whole structure in one time, but i dont know why, it only reads the first member well.. I have...
13
by: swetha | last post by:
HI Every1, I have a problem in reading a binary file. Actually i want a C program which reads in the data from a file which is in binary format and i want to update values in it. The file...
6
by: efrenba | last post by:
Hi, I came from delphi world and now I'm doing my first steps in C++. I'm using C++builder because its ide is like delphi although I'm trying to avoid the vcl. I need to insert new features...
6
by: Victory | last post by:
Hi, I need to know the compression type of jpeg (jpg) files. I am using the System.Drawing.Imaging and loading the file using an Image object. The next thing i do, is to examine the propertyItems...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.