IActiveDesignerRuntime::SetSite

Tells the designer which site interface it should use to connect event sources and sinks.

HRESULT SetSite (
   IActiveDesignerRuntimeSite *pSite
);

Parameter

pSite

[in] Pointer to an IActiveDesignerRuntimeSite interface, or NULL.

Return Values

The designer returns one of the following values:

Return Value Meaning
S_OK Success.
Other statuses Errors.

Comments

The designer implements this method.

The host calls IActiveDesignerRuntime::SetSite after it creates the run-time instance. In the pSite parameter, the host passes a pointer to an IActiveDesignerRuntimeSite interface.

The interface specified in the pointer is implemented on the site through which the designer's event sources and sinks will be connected. When the designer is ready to fire events, it calls pSite::GetAdviseSink, specifying the event source object to connect.

When the host destroys the run-time instance, it passes a NULL pointer. In response, the designer must release all of its event sink pointers.

Designers that implement this method must specify the DESIGNERFEATURE_DELAYEVENTSINKING registry flag.

Example

The following example implements the SetSite method. Because the designer need not connect the event source and sink until it is ready to fire events, the method simply stores the site pointer in the global variable m_pRuntimeSite, changing reference counts if necessary. If the host passes a NULL pointer, indicating that it has destroyed the run-time instance, the example unadvises its sinks and releases the object reference.

STDMETHODIMP CMyDesignerRuntime::SetSite
(
   IActiveDesignerRuntimeSite *pSite
)
{
   CObjSite* pObjSite = m_pObjList;
   hresult hr = S_OK;

   if(pSite == NULL){
      //Unadvise the sinks of our subobjects.
      while(pObjSite){
         hr = pObjSite->UnadviseSubSinks();
         RETURN_ON_FAILURE(hr);
         pObjSite = pObjSite->m_pNext;
      }
      //Unadvise the designer's top-level sink.
      UnadviseDesignerSink();
      m_pRuntimeSite->Release()
      }
   else {
      //Save the site pointer and add a reference to it.
      m_pRuntimeSite = pSite;
      m_pRuntimeSite->AddRef();
      }
   return hr;
}

See Also

IActiveDesignerRuntimeSite, DESIGNERFEATURE_DELAYEVENTSINKING