Re: Interesting problem: serializing in with MFC CArchive, reading out using C# BinaryReader
From: Scott McPhillips [MVP] (org-dot-mvps-at-scottmcp)
Date: 11/11/04
- Next message: Scott McPhillips [MVP]: "Re: Pumping Message in synchronous COM Read"
- Previous message: Scott McPhillips [MVP]: "Re: Scrollbars in ScrollView class."
- In reply to: RP2001: "Interesting problem: serializing in with MFC CArchive, reading out using C# BinaryReader"
- Next in thread: RP2001: "Re: Interesting problem: serializing in with MFC CArchive, reading out using C# BinaryReader"
- Reply: RP2001: "Re: Interesting problem: serializing in with MFC CArchive, reading out using C# BinaryReader"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 11 Nov 2004 18:51:03 -0500
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.
-- Scott McPhillips [VC++ MVP]
- Next message: Scott McPhillips [MVP]: "Re: Pumping Message in synchronous COM Read"
- Previous message: Scott McPhillips [MVP]: "Re: Scrollbars in ScrollView class."
- In reply to: RP2001: "Interesting problem: serializing in with MFC CArchive, reading out using C# BinaryReader"
- Next in thread: RP2001: "Re: Interesting problem: serializing in with MFC CArchive, reading out using C# BinaryReader"
- Reply: RP2001: "Re: Interesting problem: serializing in with MFC CArchive, reading out using C# BinaryReader"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|