How to AddRef an out parameter (IDispatch**) when using smart pointers
Posted on 2003-03-11
Hey, I'm using smart pointers and I need to provide the following method:
STDMETHODIMP CBrowserUIHandler::GetExternal(IDispatch** ppDispatch)
*ppDispatch = spThisDispatch;
*ppDispatch = NULL;
Before adding spThisDispatch.p->AddRef(); the app would crash. I think this makes sense, as I am making a copy of the interface, so I should call AddRef (right??). I'm wondering how this should be done using smart pointers, rather than accessing the pointer itself. This is a pretty common scenario, so I figure there must be a way to "do it right" without calling AddRef directly.