Initializes a new storage object.
HRESULT InitNew( IStorage *pStg );
An IStorage pointer to the new storage object to be initialized. The container creates a nested storage object in its storage object (see IStorage::CreateStorage). Then, the container calls the WriteClassStg function to initialize the new storage object with the object class identifier (CLSID).
This method can return the following values.
||The method completed successfully.|
||The object has already been initialized by a previous call to either the IPersistStorage::Load method or the IPersistStorage::InitNew method.|
||The storage object was not initialized due to a lack of memory.|
||The storage object was not initialized for some reason other than a lack of memory.|
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.
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 InitNew method for the object.OleCreate helper function which does the following:
- Calls the CoCreateInstance function to create an instance of the object class.
- Queries the new instance for the IPersistStorage interface.
- Calls the InitNew method to initialize the object.
- Pre-open and cache the pointers to any streams or storages that the object will need to save itself to this storage.
- Call AddRef and cache the storage pointer that is passed in.
- Call the WriteFmtUserTypeStg function to write the native clipboard format and user type string for the object to the storage object.
- Set the dirty flag for the object.
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.
|Minimum supported client||Windows 2000 Professional [desktop apps only]|
|Minimum supported server||Windows 2000 Server [desktop apps only]|