Re: Detecting navigation errors using web browser control

From: Igor Tandetnik (itandetnik_at_mvps.org)
Date: 05/13/04


Date: Thu, 13 May 2004 18:38:56 -0400

Ok, here's the situation. I don't know exactly what goes wrong, but it
has something to do with the modal message pump you run in button click
handler. It looks like you destroy WebBrowser control while it's in the
middle of doing something. When destroyed, it leaves behind a window
with window class "Internet Explorer_Hidden" (I don't know what it is
for). This window gets a ton of WM_TIMER messages, and on each such
message spawns new IE instance. I suspect that it expects to communicate
with your WebBrowser control instead, but the control has been pulled
from under its feet.

My recommendations: avoid modal message pump. Instead of creating
WebBrowser instance on the stack, create it on the heap. Initiate
navigation with Navigate method, and return from button click handler.
Eventually, the control will fire DocumentComplete event. At this point,
do whatever parsing you want to do, then post yourself a user-defined
message (with PostMessage). From this message's handler, delete the
control and any other resources you allocated for the navigation. Do not
delete it from inside DocumentComplete handler.

-- 
With best wishes,
    Igor Tandetnik
"For every complex problem, there is a solution that is simple, neat,
and wrong." H.L. Mencken
"Paul Middlin" <please don't spam me> wrote in message
news:uiuDeNTOEHA.268@TK2MSFTNGP11.phx.gbl
> Changing that certainly fixes the problem (though i'll have to do
> something about my loop that checks for completion now). Though I'm
> still a bit curious as to why, if I comment out the line altogether,
> it still does all of that new window creation silliness. Further,
> even with the fixed line, if I use an address that has a redirect for
> a 404, I get the problem.
>
> Try changing the URL to this: "http://www.microsoft.com/madeup" and
> you'll see it happen again (even with the fixed code).
>
> Sorry to take up so much of your time with this; I just need to know
> if I'm going down the wrong road. Your help is very much appreciated.
>
> "Igor Tandetnik" <itandetnik@mvps.org> wrote in message
> news:OhAmwETOEHA.2704@TK2MSFTNGP10.phx.gbl...
>> "Paul Middlin" <please don't spam me> wrote in message
>> news:%23EgKviSOEHA.1644@TK2MSFTNGP09.phx.gbl
>>> STDMETHODIMP CEventHandler::Invoke( DISPID  dispIdMember, REFIID
>>> riid, LCID lcid, WORD  wFlags, DISPPARAMS FAR*  pDispParams, VARIANT
>>> FAR*  pVarResult, EXCEPINFO FAR*  pExcepInfo, unsigned int FAR*
>>> puArgErr ) {
>>>    static DISPID nMsg = dispIdMember;
>>>    if ( dispIdMember == DISPID_NAVIGATEERROR )
>>>    {
>>>       TRACE("NAVIGATEERROR\n" );
>>>       pDispParams->rgvarg[0].boolVal = VARIANT_TRUE;
>>>    }
>>
>> That would be
>>
>> *pDispParams->rgvarg[0].pboolVal = VARIANT_TRUE;
>>
>> The parameter is passed as VT_BOOL | VT_BYREF
>> --
>> With best wishes,
>>     Igor Tandetnik
>>
>> "For every complex problem, there is a solution that is simple, neat,
>> and wrong." H.L. Mencken