At design time, a Visual Basic programmer extends the object's dynamic type information. At run time, a user can call those extensions. Therefore, in addition to providing design-time support, your designer must also provide run-time support for the extended type information.
To insert type information changes made at design time into a dispinterface, you have to override the Invoke method of the dispatch interface to which the changes were made, save the dispatch IDs (DISPIDs) of the type information changes, and be prepared to handle changed type information appropriately.
The following example shows how to handle dispatch IDs of added methods in the Invoke method of the run-time object's default dispinterface.
STDMETHODIMP CShapesDynInstCtl::Invoke(DISPID dispidMember, REFIID riid,
LCID lcid, WORD wFlags, DISPPARAMS* pdispparams,
VARIANT* pvarResult, EXCEPINFO* pexcepinfo, UINT* puArgErr)
{
HRESULT hr = E_FAIL;
int iRealID = 0;
int iCt = 0;
std::list<IUnknown *>::iterator iter;
CComPtr<IUnknown> pIUnk = NULL;
//--------------------------------------------------
// check DISPIDs
//--------------------------------------------------
if((dispidMember > DISPID_CIRCLE_BASEOFFSET) && (dispidMember <=
DISPID_RECTANGLE_BASEOFFSET))
{
if(!pvarResult)
return(E_FAIL);
iRealID = dispidMember - DISPID_CIRCLE_BASEOFFSET;
//--------------------------------------------------
// walk Circles list and look for object
//--------------------------------------------------
iter = m_listCircles.begin();
for(iCt = 1; iCt < iRealID; iCt++)
{
iter++;
}
pIUnk = *iter;
if(!pIUnk)
return(E_FAIL);
//--------------------------------------------------
// return default dispatch interface of object to
// caller.
//--------------------------------------------------
pvarResult->vt = VT_DISPATCH;
hr = pIUnk->QueryInterface(IID_IDispatch,
(void **)&(pvarResult->pdispVal));
RETURN_ON_FAILURE(hr);
return(S_OK);
}
else if((dispidMember > DISPID_RECTANGLE_BASEOFFSET) &&
(dispidMember <= DISPID_TRIANGLE_BASEOFFSET))
{
…
See Also