Initializes a new object, providing a pointer to the storage to be used for the object.
HRESULT InitNew(
IStorage *pStg //Points to the new storage object
);
A container application can call this method when it needs to initialize a new object, for example, with an InsertObject command.
An object that supports the IPersistStorage interface must have access to a valid storage object at all times while it is running. This includes the time just after the object has been created but before it has been made persistent. The object's container must provide the object with a valid IStorage pointer to the storage during this time through the call to IPersistStorage::InitNew. Depending on the container's state, a temporary file might have to be created for this purpose.
If the object wants to retain the IStorage instance, it must call IUnknown::AddRef to increment its reference count.
After the call to IPersistStorage::InitNew, the object is in either the loaded or running state. For example, if the object class has an in-process server, the object will be in the running state. However, if the object uses the default handler, the container's call to InitNew only invokes the handler's implementation which does not run the object. Later if the container runs the object, the handler calls the IPersistStorage::InitNew method for the object.
Rather than calling IPersistStorage::InitNew directly, you typically call the OleCreate helper function which does the following:
The container application should cache the IPersistStorage pointer to the object for use in later operations on the object.
An implementation of IPersistStorage::InitNew should initialize the object to its default state, taking the following steps:
The first two steps are particularly important for ensuring that the object can save itself in low memory situations. Pre-opening and holding onto pointers to the stream and storage interfaces guarantee that a save operation to this storage will not fail due to insufficient memory.
Your implementation of this method should return the CO_E_ALREADYINITIALIZED error code if it receives a call to either the IPersistStorage::InitNew method or the IPersistStorage::Load method after it is already initialized.
Windows NT: Use version 3.1 or later.
Windows: Use Windows 95 or later.
Windows CE: Unsupported.
Header: Declared in objidl.h.
IPersistStorage::Load, OleCreate, WriteFmtUserTypeStg