#include “headers.h”

HRESULT InvokeDispatch(IDispatch * pdisp, DISPID dispid, REFIID riid,
    LCID lcid, WORD flags, DISPPARAMS * pDispParams, VARIANT * pvarResult,
    EXCEPINFO * pExcepInfo, UINT * pError)

    HRESULT hr;

    // We must addref the pointer before the invocation.  Why?  Consider
    // this scenario:  the invocation calls a method which calls back
    // into the script engine, which triggers a garbage collection, which
    // does the final release on the dispatch object.  Then control returns
    // back to the call to Invoke, which dereferences its “this” pointer
    // and promptly crashes.


    hr = pdisp->Invoke(DISPID_VALUE, riid, lcid, flags, pDispParams,
        pvarResult, pExcepInfo, pError);


    return hr;

BOOL IsValidDispatch(VARIANT * pvar)
    return VT_DISPATCH == pvar->vt && NULL != pvar->pdispVal;


Comments (0)