|
|
|
date: Thu, 14 Aug 2008 00:43:29 -0700,
group: microsoft.public.inetsdk.programming.webbrowser_ctl
back
Re: WebBrowser2 PutProperty issue with Vista and IE7
"Tech" wrote in message
news:%23KHIyFe$IHA.3908@TK2MSFTNGP05.phx.gbl
> I am calling BHO function from external app. All works fine, I am
> creating a reference to IDispatch and storing it as a property. Then
> handing a call in CWebBHO::Invoke. BHO implements IObjectWithSite and
> IDispatch. However there is a problem on Vista and IE7. Basically the
> IE crashes when the browser window is closed.
I don't know what problem you have with PutProperty, but there's one
thing I noticed you are doing wrong.
IObjectWithSite::SetSite is called twice. The first time is on startup,
passing IWebBrowser2 pointer. The second time is on shut-down, right
before destroying the BHO, passing NULL as a parameter. At this point,
you must release all interface pointers you might have cached on the
browser or its document, and unadvise all event sinks. You are not doing
this.
--
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
date: Thu, 14 Aug 2008 08:28:35 -0400
author: Igor Tandetnik
Re: WebBrowser2 PutProperty issue with Vista and IE7
Igor, thank you for the info. However this turned out to be a COM error when
VariantClear(&vThis) with VT_NULL was called. Really strange.
TECH
"Igor Tandetnik" wrote in message
news:uYVY$mg$IHA.4800@TK2MSFTNGP03.phx.gbl...
> "Tech" wrote in message
> news:%23KHIyFe$IHA.3908@TK2MSFTNGP05.phx.gbl
>> I am calling BHO function from external app. All works fine, I am
>> creating a reference to IDispatch and storing it as a property. Then
>> handing a call in CWebBHO::Invoke. BHO implements IObjectWithSite and
>> IDispatch. However there is a problem on Vista and IE7. Basically the
>> IE crashes when the browser window is closed.
>
> I don't know what problem you have with PutProperty, but there's one thing
> I noticed you are doing wrong.
>
> IObjectWithSite::SetSite is called twice. The first time is on startup,
> passing IWebBrowser2 pointer. The second time is on shut-down, right
> before destroying the BHO, passing NULL as a parameter. At this point, you
> must release all interface pointers you might have cached on the browser
> or its document, and unadvise all event sinks. You are not doing this.
> --
> 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
>
>
date: Fri, 15 Aug 2008 23:52:02 -0700
author: Tech
Re: WebBrowser2 PutProperty issue with Vista and IE7
"Tech" wrote in message
news:%23V6x4H%23$IHA.5096@TK2MSFTNGP02.phx.gbl
> not really. Clearly your code works alone. But when the property is
> set the code below fails. Now comment out VariantClear(&vThis) and
> SysFreeString(bstrThisKey) in DISPID_ONQUIT and all works fine. Only
> happens on Vista and IE7.
>
> CComQIPtr<IWebBrowser2, &IID_IWebBrowser2> m_spWebBrowser2;
>
> ========= SETSITE =============
> BSTR bstrThisKey = SysAllocString(L"WebBHO_IDisp");
> VARIANT vThis;
>
> // Save this to a variant that will be referenced in IE Session
> VariantInit(&vThis);
> vThis.vt = VT_DISPATCH;
> vThis.pdispVal = static_cast<IDispatch*>(this);
You need to AddRef the pointer here. VARIANT owns its pointer.
> //Add a named property
> m_spWebBrowser2->PutProperty(bstrThisKey, vThis);
>
> VariantClear(&vThis);
And here the pointer is released, without being AddRef'ed first. At some
later point, your object will be destroyed prematurely.
> VariantInit(&vThis);
> vThis.vt = VT_NULL;
>
> // remove our reference
> m_spWebBrowser2->PutProperty(bstrThisKey, vThis);
And this, I guess, is the point where your object is destroyed
prematurely.
--
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
date: Sat, 16 Aug 2008 18:40:24 -0400
author: Igor Tandetnik
Re: WebBrowser2 PutProperty issue with Vista and IE7
Igor, spasibo! You are absolutely right. MSDN for VariantClear "if vt field
is VT_DISPATCH, the object is released"
TECH
"Igor Tandetnik" wrote in message
news:OMDjWE$$IHA.2056@TK2MSFTNGP05.phx.gbl...
> "Tech" wrote in message
> news:%23V6x4H%23$IHA.5096@TK2MSFTNGP02.phx.gbl
>> not really. Clearly your code works alone. But when the property is
>> set the code below fails. Now comment out VariantClear(&vThis) and
>> SysFreeString(bstrThisKey) in DISPID_ONQUIT and all works fine. Only
>> happens on Vista and IE7.
>>
>> CComQIPtr<IWebBrowser2, &IID_IWebBrowser2> m_spWebBrowser2;
>>
>> ========= SETSITE =============
>> BSTR bstrThisKey = SysAllocString(L"WebBHO_IDisp");
>> VARIANT vThis;
>>
>> // Save this to a variant that will be referenced in IE Session
>> VariantInit(&vThis);
>> vThis.vt = VT_DISPATCH;
>> vThis.pdispVal = static_cast<IDispatch*>(this);
>
> You need to AddRef the pointer here. VARIANT owns its pointer.
>
>> //Add a named property
>> m_spWebBrowser2->PutProperty(bstrThisKey, vThis);
>>
>> VariantClear(&vThis);
>
> And here the pointer is released, without being AddRef'ed first. At some
> later point, your object will be destroyed prematurely.
>
>> VariantInit(&vThis);
>> vThis.vt = VT_NULL;
>>
>> // remove our reference
>> m_spWebBrowser2->PutProperty(bstrThisKey, vThis);
>
> And this, I guess, is the point where your object is destroyed
> prematurely.
> --
> 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
>
date: Sat, 16 Aug 2008 23:30:50 -0700
author: Tech
|
|