Fabulous Adventures In Coding

Eric Lippert's Blog

invoke.cpp

#include "headers.h"

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

    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.

    pdisp->AddRef();

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

    pdisp->Release();

    return hr;
}

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


 

Published Tuesday, May 04, 2004 10:04 AM by Eric Lippert
Filed under:

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

No Comments

Leave a Comment

(required) 
(optional)
(required) 
Submit

This Blog

Syndication


© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Microsoft
Page view tracker