Re: Crash during "scalar deleting destructor" with IDocHostUIHandler!
Here's something I don't understand though ...
/* virtual */ HRESULT CHtmlDlg::CDocHostUIHandler::GetExternal(
/* [out] */ IDispatch __RPC_FAR *__RPC_FAR *ppDispatch)
{
TRACE(L"CDocHostUIHandler::GetExternal(ppDispatch=%p)\n", ppDispatch);
External* pExt = new External;
*ppDispatch = pExt->GetIDispatch(FALSE);
return S_OK;
}
If I specify TRUE in the GetIDispatch() call, my 'External' object never
gets deleted. If I specify FALSE, it works fine.
Is there an implicit AddRef() going on in the CCmdTarget constructor or
something?
Thanks,
Chris
"Igor Tandetnik" <itandetnik@mvps.org> wrote in message
news:OCpG6u%23HHHA.3424@TK2MSFTNGP02.phx.gbl...
"Chris Shearer Cooper" <chrisnews@sc3.net> wrote in message
news:12o3rmp8biash39@corp.supernews.com
In my MFC C++ app, I'm creating a browser window inside a dialog, and
I want to have it be able to communicate with my application. It
seems like the way to do this, is to create a class that implements
IDocHostUIHandler, pass it into the ICustomDoc::SetUIHandler(), and
then implement a dispatch class (one that implements IDispatch) which
I return when the HTML control calls my
IDocHostUIHandler::GetExternal.
You don't need to use ICustomDoc when hosting WebBrowser control. See
Driller sample for details.
However, now I have a class that derives from CCmdTarget and calls
EnableAutomation in its constructor, so it should be a happy
IDispatch kind of guy. When my IDocHostUIHandler::GetExternal is
called, I 'new' up one of those, call its InternalAddRef(), and then
store its address into the ppDispatch passed to me in the GetExternal
call. I can step through that with the debugger, but as soon as that
function returns, I get a C0000005 exception.
*ppDispatch = (IDispatch*)pExt;
The exception is due to this cast. You need to use
CCmdTarget::GetIDispatch to obtain IDispatch* pointer.
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925