Important: |
---|
This is retired content. This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This content may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist. |
This method loads an object from its existing storage.
Syntax
HRESULT Load( IStorage* pStg ); |
Parameters
- pStg
-
[in] IStoragepointer to the existing storage from which the object is to be loaded.
Return Value
The following table shows the return values for this method.
Value | Description |
---|---|
S_OK |
The object was successfully loaded. |
CO_E_ALREADYINITIALIZED |
The object has already been initialized by a previous call to the IPersistStorage::Loadmethod or the IPersistStorage::InitNewmethod. |
E_OUTOFMEMORY |
The object was not loaded due to lack of memory. |
E_FAIL |
The object was not loaded due to some reason besides a lack of memory. |
Remarks
This method initializes an object from an existing storage. The object is placed in the loaded state if this method is called by the container application. If called by the default handler, this method places the object in the running state.
Either the default handler or the object itself can hold onto the IStoragepointer while the object is loaded or running.
To determine whether the platform supports this interface, see Determining Supported COM APIs.
Notes to Callers
The container should cache the IPersistStoragepointer for use in later operations on the object.
Notes to Implementers
Your implementation should perform the following steps to load an object:
- Open the object's streams in the storage object, and read the
necessary data into the object's internal data structures.
- Clear the object's dirty flag.
- Call the
IPersistStorage::AddRefmethod and cache the passed in
storage pointer.
- Keep open and cache the pointers to any streams or storages
that the object will need to save itself to this storage.
- Perform any other default initialization required for the
object.
Steps 3 and 4 are particularly important for ensuring that the object can save itself in low memory situations. Holding onto pointers to the storage and stream interfaces guarantees 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::InitNewmethod or the IPersistStorage::Loadmethod after it is already initialized.
Requirements
Header | objidl.h, objidl.idl |
Library | ole32.lib, uuid.lib |
Windows Embedded CE | Windows CE 2.0 and later |
Windows Mobile | Windows Mobile Version 5.0 and later |