Problem?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ady

    #1

    Problem?

    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.


  • Jasper Kent

    #2
    Re: Problem?

    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!

    Comment

    • Ady

      #3
      Re: Problem?

      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" <jasper_kent@ho tmail.com> wrote in message
      news:O1lkSv3eDH A.556@TK2MSFTNG P11.phx.gbl...[color=blue]
      > 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![/color]


      Comment

      • Jasper Kent

        #4
        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!

        Comment

        • Greg Ewing [MVP]

          #5
          Re: Problem?

          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(La youtKind.Explic it)]
          public class OverlappingStru ct
          {
          [FieldOffset(0) public string WholeStruct;
          [FieldOffset(0)] public string Id;
          [FieldOffset(10)] public string Name;
          }

          Hope that helps

          --
          Greg Ewing [MVP]
          IT support built exclusively for nonprofits. 25 years of managed IT, help desk, and cybersecurity - so your team can focus on your mission.



          "Ady" <adrian.hirst@t cm.co.uk> wrote in message
          news:#emm#93eDH A.1764@TK2MSFTN GP09.phx.gbl...[color=blue]
          > 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" <jasper_kent@ho tmail.com> wrote in message
          > news:O1lkSv3eDH A.556@TK2MSFTNG P11.phx.gbl...[color=green]
          > > 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![/color]
          >
          >[/color]


          Comment

          • Morten Wennevik

            #6
            Re: Problem?

            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.Strea m stream =
            System.IO.File. Open(file, System.IO.FileM ode.Open);
            byte[] buffer;
            stream.Read(buf fer, 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(hea derStruct, 0, sizeof(headerSt ruct);

            --
            Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/

            Comment

            • Ady

              #7
              Re: Problem?

              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" <jasper_kent@ho tmail.com>
              Newsgroups: microsoft.publi c.dotnet.langua ges.csharp
              Sent: Monday, September 15, 2003 1:43 PM
              Subject: Re: Problem?

              [color=blue]
              > 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![/color]
              for it!


              Comment

              • Greg Ewing [MVP]

                #8
                Re: Problem?

                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]
                IT support built exclusively for nonprofits. 25 years of managed IT, help desk, and cybersecurity - so your team can focus on your mission.


                "Ady" <adrian.hirst@t cm.co.uk> wrote in message
                news:#nzvb54eDH A.1732@TK2MSFTN GP12.phx.gbl...[color=blue]
                > 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[/color]
                structure[color=blue]
                > 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" <jasper_kent@ho tmail.com>
                > Newsgroups: microsoft.publi c.dotnet.langua ges.csharp
                > Sent: Monday, September 15, 2003 1:43 PM
                > Subject: Re: Problem?
                >
                >[color=green]
                > > 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![/color]
                > for it!
                >
                >[/color]


                Comment

                • Jay B. Harlow [MVP - Outlook]

                  #9
                  Re: Problem?

                  Ady,[color=blue]
                  > I posted this a few days ago but it seems no one has replied any help much
                  > appreciated.[/color]
                  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.
                  [color=blue]
                  > I know that i have to serialise my class,[/color]
                  Serialization is not compatible with "pull out the value of offsetTextures
                  and add it on to the beginning of the file".
                  [color=blue]
                  > 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.[/color]
                  You will need to use the System.IO.Binar yReader class along with the
                  System.IO.Strea m 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.ReadByte s(4);
                  Ver = reader.ReadByte ();
                  header = reader.ReadByte s(90);
                  offsetTextures = reader.ReadUInt 32();

                  reader.BaseStre am.Seek(offsetT extures, SeekOrigin.Begi n);
                  [color=blue]
                  > an example would be much appreciated.[/color]
                  See my previous post for examples & further information on BinaryReaders and
                  Serialization.

                  Hope this helps
                  Jay

                  "Ady" <adrian.hirst@t cm.co.uk> wrote in message
                  news:%23c9KDo3e DHA.2360@TK2MSF TNGP10.phx.gbl. ..[color=blue]
                  > 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.
                  >
                  >[/color]


                  Comment

                  • Ady

                    #10
                    Re: Problem?

                    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(La youtKind.Explic it)]
                    public class OverlappingStru ct
                    {
                    [FieldOffset(0) public string WholeStruct;
                    [FieldOffset(0)] public string Id;
                    [FieldOffset(10)] public string Name;
                    }



                    "Greg Ewing [MVP]" <gewing@_NO_SPA M_gewing.com> wrote in message
                    news:OWsZjU5eDH A.3204@TK2MSFTN GP11.phx.gbl...[color=blue]
                    > Ady, did you see my post about overlapping structs? You could use a[/color]
                    Byte[][color=blue]
                    > 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" <adrian.hirst@t cm.co.uk> wrote in message
                    > news:#nzvb54eDH A.1732@TK2MSFTN GP12.phx.gbl...[color=green]
                    > > Right, okay what I want to do is Load in a binary data file and[/color][/color]
                    reference[color=blue][color=green]
                    > > 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[/color][/color]
                    would[color=blue][color=green]
                    > > prefer to do it in C# to keep everything consistent.
                    > >
                    > > the problem is how would i load this data in and cast somekind of[/color]
                    > structure[color=green]
                    > > to the binary data so that I could reference data with ease.
                    > >
                    > > My other problem is pulling out the 4 Byte offset for (OFFSETTEXTURES )[/color][/color]
                    and[color=blue][color=green]
                    > > adding it onto the start of the file in memory to get access to my[/color][/color]
                    texture[color=blue][color=green]
                    > > 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" <jasper_kent@ho tmail.com>
                    > > Newsgroups: microsoft.publi c.dotnet.langua ges.csharp
                    > > Sent: Monday, September 15, 2003 1:43 PM
                    > > Subject: Re: Problem?
                    > >
                    > >[color=darkred]
                    > > > 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![/color]
                    > > for it!
                    > >
                    > >[/color]
                    >
                    >[/color]


                    Comment

                    • Greg Ewing [MVP]

                      #11
                      Re: Problem?

                      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(La youtKind.Explic it)]

                      public class OverlappingStru ct

                      {

                      [FieldOffset(0)] public string WholeStruct;

                      [FieldOffset(0)] public string Id;

                      [FieldOffset(10)] public string Name;

                      }


                      --
                      Greg Ewing [MVP]
                      IT support built exclusively for nonprofits. 25 years of managed IT, help desk, and cybersecurity - so your team can focus on your mission.


                      "Ady" <adrian.hirst@t cm.co.uk> wrote in message
                      news:usUglu5eDH A.460@TK2MSFTNG P12.phx.gbl...[color=blue]
                      > 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(La youtKind.Explic it)]
                      > public class OverlappingStru ct
                      > {
                      > [FieldOffset(0) public string WholeStruct;
                      > [FieldOffset(0)] public string Id;
                      > [FieldOffset(10)] public string Name;
                      > }
                      >
                      >
                      >
                      > "Greg Ewing [MVP]" <gewing@_NO_SPA M_gewing.com> wrote in message
                      > news:OWsZjU5eDH A.3204@TK2MSFTN GP11.phx.gbl...[color=green]
                      > > Ady, did you see my post about overlapping structs? You could use a[/color]
                      > Byte[][color=green]
                      > > 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" <adrian.hirst@t cm.co.uk> wrote in message
                      > > news:#nzvb54eDH A.1732@TK2MSFTN GP12.phx.gbl...[color=darkred]
                      > > > Right, okay what I want to do is Load in a binary data file and[/color][/color]
                      > reference[color=green][color=darkred]
                      > > > the data loaded in memory as ollows, i previously showed a c++[/color][/color][/color]
                      structure[color=blue][color=green][color=darkred]
                      > > > just to show how the data is layed out not that i want to use c++, i[/color][/color]
                      > would[color=green][color=darkred]
                      > > > prefer to do it in C# to keep everything consistent.
                      > > >
                      > > > the problem is how would i load this data in and cast somekind of[/color]
                      > > structure[color=darkred]
                      > > > to the binary data so that I could reference data with ease.
                      > > >
                      > > > My other problem is pulling out the 4 Byte offset for (OFFSETTEXTURES )[/color][/color]
                      > and[color=green][color=darkred]
                      > > > adding it onto the start of the file in memory to get access to my[/color][/color]
                      > texture[color=green][color=darkred]
                      > > > 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" <jasper_kent@ho tmail.com>
                      > > > Newsgroups: microsoft.publi c.dotnet.langua ges.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[/color][/color][/color]
                      of[color=blue][color=green][color=darkred]
                      > > > > the problem.
                      > > > >
                      > > > > Thanks,
                      > > > >
                      > > > > Jasper Kent
                      > > > >
                      > > > > *** Sent via Developersdex http://www.developersdex.com ***
                      > > > > Don't just participate in USENET...get rewarded for it!
                      > > > for it!
                      > > >
                      > > >[/color]
                      > >
                      > >[/color]
                      >
                      >[/color]


                      Comment

                      Working...