473,385 Members | 1,312 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.

Problem?

Ady
Hi,

I posted this a few days ago but it seems no one has replied any help much
appreciated.

I know that i have to serialise my class,

How could I pull out the value off offsetTextures and add it on to the
beginning of the file to get the offset to the start of my texture data.

typedef struct
{
float x0, y0, z0;
float x1, y1, z1;
float x2, y2, z2;
unsigned char r0,g0,b0;
} TRIANGLE;

typedef struct
{
char Id[4];
char Ver;
char header[90];
unsigned int offsetTextures;
TRIANGLE tri[];
} MyFile;

an example would be much appreciated.

Ady.
Nov 15 '05 #1
10 1557
This looks like C++, not C#, so you may find more help in a different
newsgroup.

That said, what library are you getting your serialization class from?
MFC?

Regards,

Jasper Kent

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 15 '05 #2
Ady
No, i am trying to write a C# class that can handle loading in the data
based on that file structure, but cannot find a solution to pull out an
offset and add it onto the beggining of the file.

Thanks

Ady.

"Jasper Kent" <ja*********@hotmail.com> wrote in message
news:O1*************@TK2MSFTNGP11.phx.gbl...
This looks like C++, not C#, so you may find more help in a different
newsgroup.

That said, what library are you getting your serialization class from?
MFC?

Regards,

Jasper Kent

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 15 '05 #3
Can you write out your class examples in C#, to give a clearer idea of
the problem.

Thanks,

Jasper Kent

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 15 '05 #4
Ady, that's definitely C++ and not C#. C# doesn't support typedef's. To
get you going in the right direction here's what I would try if I understand
what you are trying to do.

Create a structure and then use the StuctLayout attribute and FieldOffset
attribute to explicitly layout the in memory size and location of your
variables. You could also create an overlapping struct architecture so that
you push your string variable from your file into the WholeStruct variable
and then access the pieces using their positions. Here's an example C#
overlapping struct.

[StructLayout(LayoutKind.Explicit)]
public class OverlappingStruct
{
[FieldOffset(0) public string WholeStruct;
[FieldOffset(0)] public string Id;
[FieldOffset(10)] public string Name;
}

Hope that helps

--
Greg Ewing [MVP]
http://www.citidc.com
"Ady" <ad**********@tcm.co.uk> wrote in message
news:#e**************@TK2MSFTNGP09.phx.gbl...
No, i am trying to write a C# class that can handle loading in the data
based on that file structure, but cannot find a solution to pull out an
offset and add it onto the beggining of the file.

Thanks

Ady.

"Jasper Kent" <ja*********@hotmail.com> wrote in message
news:O1*************@TK2MSFTNGP11.phx.gbl...
This looks like C++, not C#, so you may find more help in a different
newsgroup.

That said, what library are you getting your serialization class from?
MFC?

Regards,

Jasper Kent

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


Nov 15 '05 #5
I think he means he has a file with triangle structs and a file format
header. He needs to get the offsetTextures number to find out where the
triangles end and the textures begin (I think).

Perhaps something involving System.IO.Stream stream =
System.IO.File.Open(file, System.IO.FileMode.Open);
byte[] buffer;
stream.Read(buffer, 95, 4);

I have absolutely no idea if this works, and it looks very ugly, but the
theory is that it should read 4 bytes starting from the 95th byte of the
file. This would be the offsetTextures number. There has to be a better
way of doing this.

Maybe something that fills a header structure (without TRIANGLE[]),
or something like
stream.Read(headerStruct, 0, sizeof(headerStruct);

--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
Nov 15 '05 #6
Ady
Right, okay what I want to do is Load in a binary data file and reference
the data loaded in memory as ollows, i previously showed a c++ structure
just to show how the data is layed out not that i want to use c++, i would
prefer to do it in C# to keep everything consistent.

the problem is how would i load this data in and cast somekind of structure
to the binary data so that I could reference data with ease.

My other problem is pulling out the 4 Byte offset for (OFFSETTEXTURES) and
adding it onto the start of the file in memory to get access to my texture
data.

I hope this is a bit more clearer

Thanks

Adrian.

START OF FILE
---------------------------
4 BYTES ID
1 BYTE VER
90 BYTES HEADER
4 BYTES OFFSETTEXTURES ( RELATIVE OFFSET FROM START OF FILE)
UNKNOWN TRIANGLES[]

TEXTURES BEGIN

---------------------------

END OF FILE


----- Original Message -----
From: "Jasper Kent" <ja*********@hotmail.com>
Newsgroups: microsoft.public.dotnet.languages.csharp
Sent: Monday, September 15, 2003 1:43 PM
Subject: Re: Problem?

Can you write out your class examples in C#, to give a clearer idea of
the problem.

Thanks,

Jasper Kent

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

for it!
Nov 15 '05 #7
Ady, did you see my post about overlapping structs? You could use a Byte[]
which is the size of your struct and then have various other values
throughout to get the various data. Does that make sense? It would
basically allow you to 'force' a byte[] into a structure.

--
Greg Ewing [MVP]
http://www.citidc.com

"Ady" <ad**********@tcm.co.uk> wrote in message
news:#n**************@TK2MSFTNGP12.phx.gbl...
Right, okay what I want to do is Load in a binary data file and reference
the data loaded in memory as ollows, i previously showed a c++ structure
just to show how the data is layed out not that i want to use c++, i would
prefer to do it in C# to keep everything consistent.

the problem is how would i load this data in and cast somekind of structure to the binary data so that I could reference data with ease.

My other problem is pulling out the 4 Byte offset for (OFFSETTEXTURES) and
adding it onto the start of the file in memory to get access to my texture
data.

I hope this is a bit more clearer

Thanks

Adrian.

START OF FILE
---------------------------
4 BYTES ID
1 BYTE VER
90 BYTES HEADER
4 BYTES OFFSETTEXTURES ( RELATIVE OFFSET FROM START OF FILE)
UNKNOWN TRIANGLES[]

TEXTURES BEGIN

---------------------------

END OF FILE


----- Original Message -----
From: "Jasper Kent" <ja*********@hotmail.com>
Newsgroups: microsoft.public.dotnet.languages.csharp
Sent: Monday, September 15, 2003 1:43 PM
Subject: Re: Problem?

Can you write out your class examples in C#, to give a clearer idea of
the problem.

Thanks,

Jasper Kent

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

for it!

Nov 15 '05 #8
Ady,
I posted this a few days ago but it seems no one has replied any help much
appreciated. I have not abandon you, yet. ;-)

In .NET you will find the easiest way to do this is with Serialization.
Where you have an object graph and you read the entire graph in and write
the entire graph out.
I know that i have to serialise my class, Serialization is not compatible with "pull out the value of offsetTextures
and add it on to the beginning of the file".
How could I pull out the value off offsetTextures and add it on to the
beginning of the file to get the offset to the start of my texture data. You will need to use the System.IO.BinaryReader class along with the
System.IO.Stream class.

For starters you need to be certain that char is an 8 bit char or a 16 bit
Unicode Char. I'm treating it as an 8 bit C++ char (in other words a byte),
as your structures appear to be C++.

You can use BinaryReader something like (untested):

BinaryReader reader;
byte[] Id;
byte Ver;
byte header[];
uint offsetTextures;

Id = reader.ReadBytes(4);
Ver = reader.ReadByte();
header = reader.ReadBytes(90);
offsetTextures = reader.ReadUInt32();

reader.BaseStream.Seek(offsetTextures, SeekOrigin.Begin);
an example would be much appreciated. See my previous post for examples & further information on BinaryReaders and
Serialization.

Hope this helps
Jay

"Ady" <ad**********@tcm.co.uk> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl... Hi,

I posted this a few days ago but it seems no one has replied any help much
appreciated.

I know that i have to serialise my class,

How could I pull out the value off offsetTextures and add it on to the
beginning of the file to get the offset to the start of my texture data.

typedef struct
{
float x0, y0, z0;
float x1, y1, z1;
float x2, y2, z2;
unsigned char r0,g0,b0;
} TRIANGLE;

typedef struct
{
char Id[4];
char Ver;
char header[90];
unsigned int offsetTextures;
TRIANGLE tri[];
} MyFile;

an example would be much appreciated.

Ady.

Nov 15 '05 #9
Ady
Hi,

I understand your idea, and probably is best, thanks

Is there any documents on using these keywords on MSDN because I cant seem
to find any at all.
And when I compile I get errors

[StructLayout(LayoutKind.Explicit)]
public class OverlappingStruct
{
[FieldOffset(0) public string WholeStruct;
[FieldOffset(0)] public string Id;
[FieldOffset(10)] public string Name;
}

"Greg Ewing [MVP]" <gewing@_NO_SPAM_gewing.com> wrote in message
news:OW**************@TK2MSFTNGP11.phx.gbl...
Ady, did you see my post about overlapping structs? You could use a Byte[] which is the size of your struct and then have various other values
throughout to get the various data. Does that make sense? It would
basically allow you to 'force' a byte[] into a structure.

--
Greg Ewing [MVP]
http://www.citidc.com

"Ady" <ad**********@tcm.co.uk> wrote in message
news:#n**************@TK2MSFTNGP12.phx.gbl...
Right, okay what I want to do is Load in a binary data file and reference the data loaded in memory as ollows, i previously showed a c++ structure
just to show how the data is layed out not that i want to use c++, i would prefer to do it in C# to keep everything consistent.

the problem is how would i load this data in and cast somekind of

structure
to the binary data so that I could reference data with ease.

My other problem is pulling out the 4 Byte offset for (OFFSETTEXTURES) and adding it onto the start of the file in memory to get access to my texture data.

I hope this is a bit more clearer

Thanks

Adrian.

START OF FILE
---------------------------
4 BYTES ID
1 BYTE VER
90 BYTES HEADER
4 BYTES OFFSETTEXTURES ( RELATIVE OFFSET FROM START OF FILE)
UNKNOWN TRIANGLES[]

TEXTURES BEGIN

---------------------------

END OF FILE


----- Original Message -----
From: "Jasper Kent" <ja*********@hotmail.com>
Newsgroups: microsoft.public.dotnet.languages.csharp
Sent: Monday, September 15, 2003 1:43 PM
Subject: Re: Problem?

Can you write out your class examples in C#, to give a clearer idea of
the problem.

Thanks,

Jasper Kent

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

for it!


Nov 15 '05 #10
Yes, they are on MSDN. You can also find samples using www.google.com or
www.gotdotnet.com.

What errors do you get? I just typed that in from memory so there could be
a typo in there. I just compiled it and found I was missing a ]. Hopefully
you figured that out already. Also, don't forget to add the necessary using
statement.

using System.Runtime.InteropServices;

[StructLayout(LayoutKind.Explicit)]

public class OverlappingStruct

{

[FieldOffset(0)] public string WholeStruct;

[FieldOffset(0)] public string Id;

[FieldOffset(10)] public string Name;

}
--
Greg Ewing [MVP]
http://www.citidc.com

"Ady" <ad**********@tcm.co.uk> wrote in message
news:us*************@TK2MSFTNGP12.phx.gbl...
Hi,

I understand your idea, and probably is best, thanks

Is there any documents on using these keywords on MSDN because I cant seem
to find any at all.
And when I compile I get errors

[StructLayout(LayoutKind.Explicit)]
public class OverlappingStruct
{
[FieldOffset(0) public string WholeStruct;
[FieldOffset(0)] public string Id;
[FieldOffset(10)] public string Name;
}

"Greg Ewing [MVP]" <gewing@_NO_SPAM_gewing.com> wrote in message
news:OW**************@TK2MSFTNGP11.phx.gbl...
Ady, did you see my post about overlapping structs? You could use a

Byte[]
which is the size of your struct and then have various other values
throughout to get the various data. Does that make sense? It would
basically allow you to 'force' a byte[] into a structure.

--
Greg Ewing [MVP]
http://www.citidc.com

"Ady" <ad**********@tcm.co.uk> wrote in message
news:#n**************@TK2MSFTNGP12.phx.gbl...
Right, okay what I want to do is Load in a binary data file and reference the data loaded in memory as ollows, i previously showed a c++ structure just to show how the data is layed out not that i want to use c++, i would prefer to do it in C# to keep everything consistent.

the problem is how would i load this data in and cast somekind of

structure
to the binary data so that I could reference data with ease.

My other problem is pulling out the 4 Byte offset for (OFFSETTEXTURES) and adding it onto the start of the file in memory to get access to my texture data.

I hope this is a bit more clearer

Thanks

Adrian.

START OF FILE
---------------------------
4 BYTES ID
1 BYTE VER
90 BYTES HEADER
4 BYTES OFFSETTEXTURES ( RELATIVE OFFSET FROM START OF FILE)
UNKNOWN TRIANGLES[]

TEXTURES BEGIN

---------------------------

END OF FILE


----- Original Message -----
From: "Jasper Kent" <ja*********@hotmail.com>
Newsgroups: microsoft.public.dotnet.languages.csharp
Sent: Monday, September 15, 2003 1:43 PM
Subject: Re: Problem?
> Can you write out your class examples in C#, to give a clearer idea of > the problem.
>
> Thanks,
>
> Jasper Kent
>
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!
for it!



Nov 15 '05 #11

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

Similar topics

11
by: Kostatus | last post by:
I have a virtual function in a base class, which is then overwritten by a function of the same name in a publically derived class. When I call the function using a pointer to the derived class...
117
by: Peter Olcott | last post by:
www.halting-problem.com
18
by: Ian Stanley | last post by:
Hi, Continuing my strcat segmentation fault posting- I have a problem which occurs when appending two sting literals using strcat. I have tried to fix it by writing my own function that does the...
28
by: Jon Davis | last post by:
If I have a class with a virtual method, and a child class that overrides the virtual method, and then I create an instance of the child class AS A base class... BaseClass bc = new ChildClass();...
6
by: Ammar | last post by:
Dear All, I'm facing a small problem. I have a portal web site, that contains articles, for each article, the end user can send a comment about the article. The problem is: I the comment length...
16
by: Dany | last post by:
Our web service was working fine until we installed .net Framework 1.1 service pack 1. Uninstalling SP1 is not an option because our largest customer says service packs marked as "critical" by...
2
by: Mike Collins | last post by:
I cannot get the correct drop down list value from a drop down I have on my web form. I get the initial value that was loaded in the list. It was asked by someone else what the autopostback was...
0
by: =?Utf-8?B?am8uZWw=?= | last post by:
Hello All, I am developing an Input Methop (IM) for PocketPC / Windows Mobile (PPC/WM). On some devices the IM will not start. The IM appears in the IM-List but when it is selected from the...
1
by: sherifbk | last post by:
Problem description ============== - I have 4 clients and 1 server (SQL server) - 3 clients are Monitoring console 1 client is operation console - Monitoring console collects some data from...
9
by: AceKnocks | last post by:
I am working on a framework design problem in which I have to design a C++ based framework capable of solving three puzzles for now but actually it should work with a general puzzle of any kind and I...
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: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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.