IActiveDesigner::SaveRuntimeState

Saves the state information required to create a run-time object.

HRESULT SaveRuntimeState(
   REFIID
riidItf,
   REFIID
riidObj,
   void *
pObj
);

Parameters

riidItf

[in] Identifier of the persistence interface. Possible values are as follows:

Interface Identifier Meaning
IID_IPersistPropertyBag Textual property persistence.
IID_IPersistStorage Storage persistence.
IID_IPersistStream Stream persistence.
IID_IPersistStreamInit Stream persistence with initialization.

riidObj

[in] Identifier of the object designated by pObj. Possible values are as follows:

Interface Identifier Meaning
IID_IStorage Storage object.
IID_IStream Stream object.

pObj

[in] Pointer to a persistence object opened by the host.

Return Values

The designer returns one of the following values:

Return Value Meaning
S_OK The method succeeded.
E_FAIL The method failed for an unknown reason.
E_INVALIDARG One or more of the arguments is invalid.
E_NOTIMPL The design-time and run-time objects are the same.
E_OUTOFMEMORY Not enough memory is available to complete the operation.

Comments

The designer implements this method.

SaveRuntimeState saves information needed to create the ActiveX designer's run-time object. The Load method of the run-time object's persistence interface must be able to load this information when the run-time object is created.

Before calling SaveRuntimeState, the host calls QueryPersistenceInterface to determine which persistence interface to use.

Example

The following example checks to see what type of interface the host has passed and sets up the pointer appropriately. For storage persistence, it opens a stream within the storage object and writes the data to the stream.

STDMETHODIMP CMyDesigner::SaveRuntimeState
(
  REFIID riidItf,
  REFIID riidObj,
  void  *pMedium
)
{
  IStream *pStream;
  long   l;
  HRESULT  hr;
  LPWSTR pwsz;

  // Get an IStream.
  if (riid == IID_IStream) {
    pStream = (IStream *)pMedium;
    pStream->AddRef();
    }
  else if (riid == IID_IStorage) {
    // Save to the CONTENTS stream.
   hr = ((IStorage *)pMedium)->
            CreateStream(s_wszRuntimeSaveStream, 
               STGM_WRITE | STGM_SHARE_EXCLUSIVE | STGM_CREATE, 
               0, 0, &pStream);
          RETURN_ON_FAILURE(hr);
         }
   else {
   FAIL("Unsupported persistence interface!");
   }
  // Save some standard state. The Load
  // routine will look for it in the stream.
  hr = SaveStandardState(pStream);
  RETURN_ON_FAILURE(hr);

  // Save property.  
  if (m_bstrMyString) {
    pwsz = m_bstrMyString;
    l = SysStringLen(m_bstrMyString) + 1;
  } else {
    pwsz = L"";
    l = 1;
  }

  hr = pStream->Write(&l, sizeof(l), NULL);
  RETURN_ON_FAILURE(hr);
  hr = pStream->Write(pwsz, l * sizeof(WCHAR), NULL);

  pStream->Release();
  return hr;
}