Doing the Right Thing with IPersistStream

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



I have a custom data log file format that I want to turn into a COM
object so it is "self-aware" and can provide some extraction facilities
(e.g. if there are 7 unsigned 16-bit ints being logged, I want to
return the Nth thing as a SAFEARRAY of VT_UI2). Goody!

I guess my (general) question is, what are some Right Things to do so
that it works well with the built-in COM features?

Some specific questions:

Suppose I have implemented a COM object CJasonLog with interface
IJasonLog that derives from IPersistStream. (or should it have
IJasonLog and IPersistStream as separate interfaces?)

If I assign a pointer to IJasonLog into a CComVariant, and something
calls CComVariant::ReadFromStream, will that use my IPersistStream
implementation? Or do I need to provide another interface instead?

How do I get an IStream * from a filename, anyway? is there a COM
equivalent to fopen()?

Strategies for handling persistence for vectors of the object's
members:
(a) write the # of members to the stream, then write each member to the
stream
(b) write each member to the stream, then write a "terminator" object
to the stream so that when the stream is re-opened later, the object
can know when it's done.

Is (b) an acceptible practice? The reason I'm asking is that as I
create my datalog object in memory, as I go I will probably be
shadowing it to a disk file for each new section of the datalog, and I
don't know in advance how many datalog sections there will be.

.



Relevant Pages

  • Re: Binary serialization
    ... Previously I would use a file write routine that worked ... DATA members from the class in question the method of writing each ... the base class where you collect the data in to a byte array which is ... then written to the stream by the base class. ...
    (microsoft.public.dotnet.general)
  • Re: Design question...
    ... All members are static. ... For some reason I'm stuck on the following design question. ... Should this stream be created every time the log needs to be written, or should the stream be a member variable of the logging class and only be opened and closed once per application lifetime. ... This seems like a simple question but for some reason I can't decide which is the right way to do this. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Hand Waving vs. Rigorous Analysis... (was Security Engineeringvs. Crypto Academics...)
    ... > to key management as I understand the term. ... and old members may be revoked. ... working system where those actions could be done in real time. ... stream, and unauthorised ones can. ...
    (sci.crypt)
  • RE: raw data and streams
    ... Ok, I was looking at my file stream for the members, the memory stream allows you to write bytes to the stream already. ...
    (microsoft.public.dotnet.languages.csharp)