RameshK

Has anyone seen this behavior In IE7, when get_Document is called on IWEBBrowser2, it returns NULL.

Basically, I am doing the following in the OnCreate of the explorer bar (my explorer bar is based on an HTML control):

CAxWindow wnd(m_hWnd);

HRESULT hr = wnd.CreateControl(IDH_HTML_SPLASH1);

CComPtr<IDispatch> pHtmlDispatch;
CComPtr<IHTMLDocument2> pHtmlDocument;

hr = wnd.QueryControl(IID_IWebBrowser2, (void**)&m_spBrowser);


if (m_spBrowser) m_spBrowser->get_Document(&pHtmlDispatch);

After the above last line, pHtmlDispatch is NULL. This seems to happen only in IE7. What could be the reason And if pHtmlDispatch is NULL how else can I get hold of the document Thanks



Re: Internet Explorer Extension Development get_Document returns NULL in IE7

Reza Nourai - MSFT

You shouldn't be seeing this behavior.

Have you made any navigations yet when this code is called The reason being that upon creating a browser object, the document is empty until the first navigation, therefore possibly returning NULL.

Please explain more of the code and I can try to figure out what is wrong.

-Reza





Re: Internet Explorer Extension Development get_Document returns NULL in IE7

RameshK

Reza,

Thanks for the quick reply. This is related to my right click issue on IE7 which I have posted in another thread. I have made part of the right click to work in IE7 by getting the document object, getting the location from it and assigning a different URL to it. The part that is not working is when the explorer bar is in a closed state and when I am trying to invoke it using ShowExplorerBar from a BHO. And that is what I have posted in this thread. The reason it is not working is because I am unable to get to the document object and IWEBBrowser2.Navigate doesn't go through also.

Now, here is the flow (explorer bar is closed when the browser is started):

- The right click is interpretted by BHO, it identifies that the bar is closed from a registry key, and invokes ShowBrowserBar with the ID of the explorer bar

- The call gets into SetSite of explorer bar

- SetSite calls QI on pUnkSite to get parent window

CComPtr <IOleWindow> pOleWindow;

pUnkSite->QueryInterface(IID_IOleWindow, (LPVOID *) &pOleWIndow)

pOleWIndow->GetWindow(&m_hwndParent);

- Now SetSite calls Create

RECT rc;

::GetClientRect(m_hwdParent, &rc);

Create(m_hwndParent, rc);

- Now call gets into OnCreate where I am trying to use the already posted code to get the document which returns NULL

CAxWindow wnd(m_hwnd);

HRESULT hr = wnd.CreateControl(IDH_HTML_SPLASH1);

wnd.QueryControl(IID_IWebBrowser2, (void **)&m_spBrowser);

m_spBrowser->get_Document(&pHtmlDispatch); -------> returns pHtmlDispatch as NULL

I hope I have given you enough information. The interesting thing is, the same flow works when the explorer bar opens in an expanded state when the browser is open (this happens when the bar was in an expanded state when the browser was closed last time).

Is this related to tab based windows in IE7 Am I supposed to get the parent window through another mechanism

Thanks again.

K. Ramesh






Re: Internet Explorer Extension Development get_Document returns NULL in IE7

RameshK

Reza,


One additional thing that I just noticed is that the CreateControl call returns a 24278028 instead of S_OK, ONLY when the explorer bar is invoked using ShowBrowserBar. If the bar is opened automatically when the browser opens, then this call returns S_OK. I hope you will be able to solve this mystery for me so that I can move on with this Right Click thing which has been killing me for past couple of weeks!


Thanks and appreciate your help.

K. Ramesh





Re: Internet Explorer Extension Development get_Document returns NULL in IE7

RameshK

Reza,

Any feedback on the issue Do you need any more information

Thanks

Ramesh






Re: Internet Explorer Extension Development get_Document returns NULL in IE7

Reza Nourai - MSFT

I think the problem can be narrowed down to the CreateControl section and surrounding code then, considering that in the same cases that the code doesn't work, CreateControl returns a failure code. So let's start there.

Are you properly checking that m_hwnd is non-NULL and valid before the CAxWindow constructor I find it very interesting that the problem only occurs when IE starts with your explorer bar hidden, then you show it yourself. That may somehow be linked to the HWND issue.

I will try to build a quick test app similar to what you are doing and see if I can narrow the problem down.

-Reza





Re: Internet Explorer Extension Development get_Document returns NULL in IE7

RameshK

Reza,


Thanks for the response again. I did a quick check and m_hWnd is indeed 0x00000000. I don't know why though.


Thanks





Re: Internet Explorer Extension Development get_Document returns NULL in IE7

RameshK

Reza,

Please ignore my previous posting. I didn't do proper debugging to check m_hWnd. Also, in my previous posting I stated that CreateControl was returning a postive number which is also not correct. CreateControl IS properly returning S_OK and m_hWnd does have a valid pointer. But still, get_Document returns NULL.

Sorry to have led you in the wrong path. I apologize for that.

But there is definitely something different in invoking the Explorer Bar using ShowBrowserBar. The same bar opens properly when I click on the tool bar button.

Has it got anything to do with how we get hold of the main browser in the BHO In other words, do we have to do something special for IE7 to get hold of the browser for the active tab Or, the same BHO code that works in IE6 should also work in IE7


waiting for your test results ...






Re: Internet Explorer Extension Development get_Document returns NULL in IE7

Reza Nourai - MSFT

A few more quick things to check...

1. How are you invoking the ShowBrowserBar What IWebBrowser2 pointer are you calling it on

2. Try calling get_Parent or get_TopLevelContainer to verify that this is the top level IWebBrowser2.

3. If it's not (from 2), then try getting the Container via get_Container and then querying that for an IWebBrowser2 interface.

Let me know what you find, and I will try to make time to get that test app written.

-Reza





Re: Internet Explorer Extension Development get_Document returns NULL in IE7

RameshK

Reza,

I am posting the entire BHO code for clarity on what is going on:


CBho::CBho()
{
m_pMainWB = NULL; // Pointer to IWebBrowser2 in the main window
m_pSite = NULL;
}

STDMETHODIMP CBho::Invoke(DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
{
try
{
if (IID_NULL != riid)
return DISP_E_UNKNOWNINTERFACE;
if (!pDispParams)
return DISP_E_PARAMNOTOPTIONAL;

switch (dispIdMember)
{
case DISPID_BEFORENAVIGATE2: //OnBeforeNavigate2
{
CUrlEx Url;
CComBSTR bstrUrl(((*pDispParams).rgvarg)[5].pvarVal->bstrVal);
CString fullUrl;
fullUrl.Format("%S", bstrUrl);

if (! Url.CrackUrl(fullUrl, 0))
break;

CString searchVal;
bool paramFound=false;
paramFound=Url.GetParameters().Lookup("myParameter", searchVal);

if (paramFound) {
//this reads the state of expBar from a reg key
bool minimized = settings.IsPFMinimized();
// if ExpBar is in a minimized state, then launch it
if (minimized) {
ShowExpBar();
}
}
}
break;

default:
{
return DISP_E_MEMBERNOTFOUND;
}
}
}
catch (CWin32Exception * ex)
{
HRESULT hr = ex->GetResult();
ex->Delete();
return hr;
}
catch (CException * ex)
{
ex->Delete();
return E_FAIL;
}
catch (...)
{
return E_FAIL;
}

return S_OK;
}
STDMETHODIMP CBho::SetSite(IUnknown *pUnkSite)
{
HRESULT hr = S_OK;

if (! pUnkSite)
{
// unloading
if (m_pMainWB)
{
AtlUnadvise(m_pMainWB, DIID_DWebBrowserEvents2, m_dwCookie);
}

m_pSite = NULL;
m_pMainWB = NULL;
}
else
{
m_pSite = NULL;
m_pMainWB = NULL;

CComPtr<IOleCommandTarget> pCmdTarget;
CComPtr<IServiceProvider> pSP;

HRESULT hr = pUnkSite->QueryInterface(IID_IInputObjectSite, (LPVOID *) & m_pSite);
hr = pUnkSite->QueryInterface(IID_IOleCommandTarget, (LPVOID *) & pCmdTarget);
if (SUCCEEDED(hr)) hr = pCmdTarget->QueryInterface(IID_IServiceProvider, (LPVOID *) & pSP);
if (SUCCEEDED(hr)) hr = pSP->QueryService(SID_SWebBrowserApp, IID_IWebBrowser2, (LPVOID * ) & m_pMainWB);

//hr = pUnkSite->QueryInterface(IID_IWebBrowser2, (LPVOID *) &m_pMainWB);

if (SUCCEEDED(hr))
{
if (m_pMainWB != NULL)
{
AtlAdvise(m_pMainWB, GetUnknown(), DIID_DWebBrowserEvents2, &m_dwCookie);
bool minimized = settings.IsPFMinimized();
// if ExpBar is in a minimized state, don't try to launch it
if (!minimized) {
ShowExpBar();
}
}
}
}

return S_OK;
}

STDMETHODIMP CBho::GetSite(REFIID riid, void ** ppvSite)
{
if (! ppvSite)
{
_ASSERT(ppvSite);
return E_INVALIDARG;
}

* ppvSite = NULL;

if (m_pSite)
{
return m_pSite->QueryInterface(riid, ppvSite);
}

return E_FAIL;
}

void CBho::ShowExpBar() {

//Display ExpBar Explorer bar object
VARIANT vtBandGUID, vtShow;
vtBandGUID.vt = VT_BSTR;
vtBandGUID.bstrVal = SysAllocString(OLESTR("{F6DFE485-B556-4D9D-ADBC-AF4D52D5C123}"));
vtShow.vt = VT_BOOL;
vtShow.boolVal = VARIANT_TRUE;
m_pMainWB->ShowBrowserBar(&vtBandGUID, &vtShow, 0);

SysFreeString(vtBandGUID.bstrVal);

}


I will try your suggestions and get back to you soon.

Thanks again for your timely support.





Re: Internet Explorer Extension Development get_Document returns NULL in IE7

RameshK

When I tried get_TopLevelContainer in my BHOs SetSite method it returns true. I believe I was testing it correctly ...

I was using the following code to test it in SetSite:

hr = pUnkSite->QueryInterface(IID_IWebBrowser2, (LPVOID *) &m_pMainWB);

VARIANT_BOOL isTop;

m_pMainWB->get_TopLevelContainer(&isTop);

if (isTop == VARIANT_TRUE) blah blah ...

But the point is, ShowBrowserBar itself seems to work since it opens the Explorer Bar and the calls get into Explorer Bar code. SetSite and OnCreate of Explorer Bar are correctly called. Only problem is when trying to do a get_Document on the browser object in Explorer Bar. If you notice my other thread on right click search, invoking a Navigate on the same browser object returns -2147024726. Not sure if the two are related ...






Re: Internet Explorer Extension Development get_Document returns NULL in IE7

RameshK

Reza,

Any luck You are the only hope I have at this point! Thanks






Re: Internet Explorer Extension Development get_Document returns NULL in IE7

RameshK

Is this a dead thread now (similar to my other posting on right click search) Reza, I am dead in the water. Would you mind posting something/anything just so that I would know someone is looking into this issue, please Thanks again and I appreciate your help.








Re: Internet Explorer Extension Development get_Document returns NULL in IE7

Reza Nourai - MSFT

Did you say that this worked on IE6

I just took another look at the code and thought of something else. It is possible that the window isn't fully initialized during the OnCreate call. This is where the window is being constructed after all, and the inner document may not be ready yet. I'm not sure why it would work when the explorer bar starts off open, but maybe IE has already created and loaded your resources at that point. My suggestion is try overriding an OnInitialUpdate or OnShowWindow and try getting the document there. See if that helps.

-Reza





Re: Internet Explorer Extension Development get_Document returns NULL in IE7

RameshK

Reza,


I tried your suggestion. It doesn't seem to help! I overrid( ) OnShowWindow and called my navigate method from there which in turn will try to get the document and do a Navigate2. I still got the same result. I don't know what else to try. Thanks

Are you able to reproduce what I am facing

K. Ramesh