CComDispatchDriver::GetProperty

HRESULT GetProperty( DISPID dwDispID, VARIANT* var );

static HRESULT GetProperty( IDispatch* pDisp, DISPID dwDispID, VARIANT* var );

Return Value

One of the standard HRESULT values.

Parameters

dwDispID

[in] The DISPID of the property to be retrieved. The DISPID can be obtained from IDispatch::GetIDsOfNames.

var

[out] Pointer to where the property value is to be stored.

pDisp

[in] Pointer to the IDispatch interface.

Remarks

Gets the value of the property identified by dwDispID. If you supply pDisp, that IDispatch pointer is used. If you do not, the IDispatch pointer contained in the data member p is used.

The following example shows a call to the static version of GetProperty. This code is used to implement IPersistStreamInitImpl::Save.

CComPtr<IDispatch> pDispatch;
const IID* piidOld = NULL;
for(int i = 0; pMap[i].pclsidPropPage != NULL; i++)
               // pMap is a pointer to an array of 
               // ATL_PROPMAP_ENTRY structures
{
   if (pMap[i].szDesc == NULL)
      continue;
   CComVariant var;
   if(pMap[i].piidDispatch != piidOld)
   {
      if(FAILED(ControlQueryInterface(*pMap[i].piidDispatch, 
                                (void**)&pDispatch)))
      {
         ATLTRACE(_T("Failed to get a dispatch pointer 
                  for property #%i\n"), i);
         hr = E_FAIL;
         break;
      }
      piidOld = pMap[i].piidDispatch;
   }
   if (FAILED(CComDispatchDriver::GetProperty(pDispatch, 
                               pMap[i].dispid, &var)))
   {
      ATLTRACE(_T("Invoked failed on DISPID %x\n"), 
               pMap[i].dispid);
      hr = E_FAIL;
      break;
   }
   HRESULT hr = var.WriteToStream(pStm);
   if (FAILED(hr))
      break;
}

CComDispatchDriver OverviewClass Members

See Also   CComDispatchDriver::PutProperty