1

I am trying to read a binary file in C# which has been written actually using CArchive. I have done most of the part but stuck in reading an object. Instead of writing bool, int, double object has been written into binary.

http://msdn.microsoft.com/en-us/library/3bfsbt0t(v=vs.110).aspx

So original code is something like this.

MyClass myObject;
if (archive.IsStoring()
    archive << myObject;
else
    archive >> myOjbect;

So question is how can I translate this piece of code in C#.

void Read(BinaryReader reader)
{
    // Read MyClass object here.
}
fhnaseer
  • 7,159
  • 16
  • 60
  • 112

1 Answers1

0

You'll need to create a comparable C# object (you might want to use C++/CLI) and construct it from the file.

It would help if you specified what myObject is.

zmbq
  • 38,013
  • 14
  • 101
  • 171
  • I didn't get it. Can you elaborate it? – fhnaseer Jul 30 '13 at 06:12
  • I have tried some more debugging, when writing object Serialize method is called and it writes int, doubles in it. But when reading it doesn't read that in order. I skipped some bytes and then tried to read, and it worked. Looks like archive >> myObject writes something extra (Class name I guess). – fhnaseer Jul 30 '13 at 06:21
  • Hi @fhnaseer , I am also converting a MFC Serialization to C# . How did you figure out how the data was saved , and read via CArchive. – Sujay Ghosh Jan 17 '22 at 08:06