Re: Interesting problem: serializing in with MFC CArchive, reading out using C# BinaryReader

From: RP2001 (ratcharit_at_gmail.com)
Date: 11/12/04


Date: 12 Nov 2004 07:31:27 -0800


"Scott McPhillips [MVP]" <org-dot-mvps-at-scottmcp> wrote in message news:<e6CJzmEyEHA.2540@TK2MSFTNGP09.phx.gbl>...
> RP2001 wrote:
>
> > I've serialized in various variables of various types (mainly CString,
> > int, double) into an instantiated MFC CArchive class and saved it as a
> > binary file.
> >
> > I am able to open the binary file and read out the individual
> > variables fine with an MFC application. However I cannot read the
> > binary file correctly with a C#.NET application, where I'm using the
> > BinaryReader Class. Doing some debugging I noticed that the problem
> > occured at this C# line of code:
> >
> > my_variable_of_type_CString =
> > instantiated_CSharp_binaryreader.ReadString();
> >
> > When this line of code execute, the binary reads out the ENTIRE
> > remainder of the file. So I thought is this one of those hairy, good
> > old string termination issues, but I've checked the byte representing
> > the string termination and it's there.
> >
>
> Actually, a CString in a CArchive file does not have a terminator. You
> are assuming that the C# ReadString knows how MFC encodes a string in a
> CArchive. I don't know what C# does, but this seems a very unlikely
> assumption. CArchive prefixes the string with its length, and the
> length of the length field is variable and binary. So you have a lot
> more work to do - translating the CArchive code - before you can expect
> to properly interpret a binary image of a CArchive.

Huh . . . What is the byte that I see after the CString that is being
interpreted as ASCII "\v"? Isn't that some sort of string termination?
Thanks for your input, Scott.



Relevant Pages

  • Re: Interesting problem: serializing in with MFC CArchive, reading out using C# BinaryReader
    ... > I am able to open the binary file and read out the individual ... > variables fine with an MFC application. ... > BinaryReader Class. ... > the string termination and it's there. ...
    (microsoft.public.vc.mfc)
  • Re: Reading structures from a binary file
    ... Looking at a couple of books seemed to suggest that deserialize was a ... good and efficient approach to reading structures from a binary file. ... In other words, serialize seems to add ... Yes I'll certainly try BinaryReader as a next step, ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Reading structures from a binary file
    ... I would use either a BinaryReader or a Stream & System.BitConverter. ... If the BinaryReader was a performance problem, then I would use a different ... > binary file, but I'm not quite sure how to handle it thereafter. ... The one caveat to watch for with the BinaryReader is how strings are ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Interesting problem: serializing in with MFC CArchive, reading out using C# BinaryReader
    ... I solved it by looking into the MFC ... public string ReadCString() ... >> I am able to open the binary file and read out the individual ... >> old string termination issues, but I've checked the byte representing ...
    (microsoft.public.dotnet.languages.csharp)

Loading