CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2004
    Posts
    19

    Post How to write a struct into a file?

    For example, a .bmp file has a header containing essential info to describe the bitmap. In C++, it is encapsulated into a struct something like:

    struct BMP_HDR
    {
    char signature[4];
    long hdr_size;
    ...........
    }

    Write the struct into a file by using the code:
    BMP_HDR hdr;
    ........// filling the hdr struct
    CFile file;
    file.Open(...);
    file.Write(&hdr, sizeof(hdr));

    So, how to do this in C# to achieve the same goal?
    By the way, the sizeof() operator is NOT recommended in managed code in C#, is it?

    Thanks!!!

  2. #2
    Join Date
    Dec 2002
    Location
    La Plata, Buenos Aires
    Posts
    615

    Re: How to write a struct into a file?

    if it's an struct with ,e.g records and fields, you can dump out that into an XML file. Just search your documentation for the XmlDocument functions.

    Also look out for Serialization topic.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured