SaveRuntimeState Method

Saves the information about the run-time persistence interface needed to create the design-time ActiveX control.

Visual Basic Syntax

This method is implemented automatically by Visual Basic when you include IActvieDesigner as a reference in your project.

Visual C++ Syntax

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

Parameters

riidItf

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

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

Identifier Meaning
IDD_IStorage Storage object
IDD_IStream Stream object

*pObj

Pointer to a persistence object opened by the host.

Return values

The return value obtained from HRESULT is one of the following:

Return value Meaning
S_OK Success
E_FAIL Failure for an unknown reason
E_INVALIDARG One or more of the arguments are invalid
E_NOTIMPL The design-time and the run-time objects are the same
E_OUTOFMEMORY Out of memory

Remarks

This IActiveDesigner method is general and allows for many types of design-time ActiveX controls that persist their state through any OLE persistence medium. Design-time controls respond to this method using the IID_IPersistTextStream persistence format. The run-time text is written into an IStream medium. The text must be UNICODE.

Design-time controls return text as their run-time persistence. As such, they support writing text through IPersistTextStream persistence into an IStream medium.

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.

C++ Language 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 CSinkDTC::SaveRuntimeState(REFIID iidPersist, REFIID iidObjStgMed, void * pObjStgMed)
{
   HRESULT         hr = S_OK;
   IStream *      pStm;
   ULONG         cbWritten;
   CComBSTR      sRuntimeText;

   if (iidPersist != IID_IPersistTextStream)
      return E_INVALIDARG;
   if (iidObjStgMed != IID_IStream)
      return E_INVALIDARG;

   pStm = static_cast<IStream *>(pObjStgMed);

   sRuntimeText =  L"<B>This is the chosen fruit: ";
   sRuntimeText += m_sSelectedFruit;
   sRuntimeText += "</B><P>";

   hr = pStm->Write(
         sRuntimeText.m_str,
         sRuntimeText.Length() * sizeof (OLECHAR),
         &cbWritten);

   return hr;
}