I have an existing application that uses CArchive to serialize a object structure to a file. I am wondering if can replace the usage of CArchive with some custom class to write to a database the same way that things are serialized. Before I go about figuring if this is doable I was wondering if other people have done the same- what is the best approach to this problem? I would like to be able to create a drop in replacement for the usage of CArchive so that the existing object structure would simply read/write to/from a database rather than a serialized file. Is it as simple as overwriting the Serialize method for each class?
Short answer: forget it.
Longer answer:
CArchive doesn't have a single virtual member. Even it's destructor isn't virtual, which means you're not supposed to derive from that class (C# programmers say sealed).
There's only one possibility that I can think of to customize CArchive's work (and without rewriting the whole serialization code in CDocument): Construct your CArchive object by passing it a pointer to CFile derived class that would handle the data connection for you.
From there on, how you control your database by simply overriding CFile's Read() and Write() is beyond my imagination :-(