Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
inet
active_desktop
active_scrptng
asp.components
asp.db
asp.general
comctl32
comp.packaging
components.dev
dbweb
dhtml_editing
docobjects
html_authoring
html_objmodel
iis
iis.ftp
iis.security
iis.smtp_nntp
indexserver
misc
mshtml_hosting
scripting.jscript
scripting.vbscript
sdk_setup
shell_objmodel
urlmonikers
webbrowser_ctl
wininet
  
 
date: Thu, 14 Aug 2008 00:43:29 -0700,    group: microsoft.public.inetsdk.programming.webbrowser_ctl        back       


WebBrowser2 PutProperty issue with Vista and IE7   
Hi,

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. The code is below. I tried to set the custom property to 
NULL (CWebBHO::ReferenceMe(true) by handling DISPID_ONQUIT but that does not 
fix it. I guess next step is to do debugging with symbols but anyways wanted 
to ask first. Building and compiling is done in VC6 on XP.

Anybody could shed a light on the problem?

TECH

///////// start code //////////
STDMETHODIMP CWebBHO::SetSite(IUnknown *pUnkSite)
{
    USES_CONVERSION; //CA2W is called
    HRESULT hr = S_OK;
    // Retrieve and store the IWebBrowser2 pointer
    m_spWebBrowser2 = pUnkSite;
    if (m_spWebBrowser2 == NULL)
      return E_INVALIDARG;
    // IConnectionPointerContainer pointer
    m_spCPC = m_spWebBrowser2;
    if (m_spCPC == NULL)
      return E_POINTER;
    // Registers the IE session to allow external call i
    hr = ReferenceMe(false);
    if (FAILED(hr))
       return S_FALSE
.......................

HRESULT CWebBHO::ReferenceMe(bool bRemove)
{
    BSTR bstrThisKey = SysAllocString(L"WebBHO_IDisp");
    VARIANT vThis;
    HRESULT hr = S_FALSE;
    if (!bRemove)
    {
        if (!m_spWebBrowser2)
        goto Cleanup;
        // Save this to a variant that will be referenced in IE Session
        VariantInit(&vThis);
        vThis.vt = VT_DISPATCH;
        vThis.pdispVal = static_cast<IDispatch*>(this);
        // Add our this pointer to IE session by adding a named property
        if (FAILED( m_spWebBrowser2->PutProperty(bstrThisKey, vThis) ))
            goto Cleanup;
    }
    else
    {
        VariantInit(&vThis);
        vThis.vt = VT_NULL;
        // Time to release, remove our reference
        if (FAILED( m_spWebBrowser2->PutProperty(bstrThisKey, vThis) ))
            goto Cleanup;
    }
    hr = S_OK;
Cleanup:
    VariantClear(&vThis);
    SysFreeString(bstrThisKey);
    return hr;
}
date: Thu, 14 Aug 2008 00:43:29 -0700   author:   Tech

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:%23ZcwUy2$IHA.4616@TK2MSFTNGP06.phx.gbl
> 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.

I'm not sure I understand. Are you saying this code crashes?

VARIANT v;
v.vt = VT_NULL;
VariantClear(&v);

I don't see anything wrong with this. Seems to be working fine for me.
-- 
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 09:05:34 -0400   author:   Igor Tandetnik

Re: WebBrowser2 PutProperty issue with Vista and IE7   
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);

  //Add a named property
  m_spWebBrowser2->PutProperty(bstrThisKey, vThis);

  VariantClear(&vThis);
  SysFreeString(bstrThisKey);

===== INVOKE ==========
 else if(dispidMember == DISPID_ONQUIT)
    {
        BSTR bstrThisKey = SysAllocString(L"WebBHO_IDisp");
        VARIANT vThis;
        HRESULT hr = S_FALSE;

        VariantInit(&vThis);
        vThis.vt = VT_NULL;

        //  remove our reference
        m_spWebBrowser2->PutProperty(bstrThisKey, vThis);

        VariantClear(&vThis);
        SysFreeString(bstrThisKey);
        return S_OK;
    }


"Igor Tandetnik"  wrote in message
news:%239XfID6$IHA.4684@TK2MSFTNGP06.phx.gbl...
> "Tech"  wrote in message
> news:%23ZcwUy2$IHA.4616@TK2MSFTNGP06.phx.gbl
>> 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.
>
> I'm not sure I understand. Are you saying this code crashes?
>
> VARIANT v;
> v.vt = VT_NULL;
> VariantClear(&v);
>
> I don't see anything wrong with this. Seems to be working fine for me.
> -- 
> 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 13:52:21 -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

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us