Implementing the Persistence Interfaces

The visual designer must implement IPersist and at least one of its derived interfaces: IPersistStreamInit, IPersistStream, and IPersistStorage.

The IPersist interface is the base interface for the other three interfaces. It has one method, GetClassID, which returns the class identifier of an object that implements one or more of the other persistence interfaces. For an ActiveX Designer, this method should return the class identifier (CLSID) of the visual designer.

You also have to implement one or more of the other persistence interfaces, depending on the type and size of the run-time objects you expect to be built from your ActiveX Designer, and which hosts will use it.

Hosts request a persistence interface by iteratively calling QueryInterface on the ActiveX Designer object, passing interface identifiers (IIDs) in order of preference. Different hosts may request different persistence interfaces. In general, IPersistStreamInit is the preferred interface because it is the fastest and because its InitNew method allows the object to avoid loading itself twice (when the instance is created and again when the Load method is called). IPersistStream is fast, but does not include an InitNew method, so you can't take advantage of this loading optimization. Some hosts, however, use IPersistStorage. Although storage persistence requires significantly more overhead, some applications may need structured storage, and some subobjects may require it.

In the visual designer, you may also want to implement IPersistPropertyBag, which saves information about properties and methods in a textual format. See the "Knowledge Base" section of the Microsoft Developer Network (MSDN) Library for more information on the IPersistPropertyBag interface.