Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Internet Explorer Script Error & IDocHostUIHandler

326 views
Skip to first unread message

Jeffrey Rich

unread,
Oct 10, 2002, 7:32:20 PM10/10/02
to
My problem in a nutshell is that I am implementing IDocHostUIHandler on a
BHO and using ICustomDoc interface to set the UIHandler in the
OnNavigateComplete2 event of DWebBrowserEvents2. If I call the
SetUIHandler, I will get Internet Explorer Script Error popups regardless of
whether I have disable script debugging check on the <Tools<Internet
Options<Advanced Tab. However if I comment out the line I no longer get the
popups.

Basically all I am overloading on IDocHostUIHandler is ShowContextMenu
function. In the other functions I either return E_NOTIMPL or S_FALSE and I
set out values to NULL.

The following is the relevant code.

void CExplorerHelper::OnNavigateComplete2(/*[in]*/ IDispatch* pDisp,
/*[in]*/ VARIANT* URL)
{
CComPtr<IDispatch> pDocDisp;
HRESULT hr;
hr = m_spWebBrowser2->get_Document(&pDocDisp);
if(SUCCEEDED(hr) && pDocDisp.p)
{
CComPtr<ICustomDoc> pCustDoc;
hr = pDocDisp->QueryInterface(__uuidof(ICustomDoc),(void **)&pCustDoc);
if(SUCCEEDED(hr))
{
pCustDoc->SetUIHandler(this); //this Implements IDocHostUIHandler
}
}
//IDocHostUIHandler
}

STDMETHODIMP CExplorerHelper::GetHostInfo(
/* [out][in] */ DOCHOSTUIINFO *pInfo)
{
//pInfo->cbSize = sizeof(DOCHOSTUIINFO);

// Turn off the 3D border and scroll bar.
//pInfo->dwFlags |= DOCHOSTUIFLAG_NO3DBORDER|
// DOCHOSTUIFLAG_SCROLL_NO;

return S_FALSE;

}

STDMETHODIMP CExplorerHelper::ShowUI(
/* [in] */ DWORD dwID,
/* [in] */ IOleInPlaceActiveObject *pActiveObject,
/* [in] */ IOleCommandTarget *pCommandTarget,
/* [in] */ IOleInPlaceFrame *pFrame,
/* [in] */ IOleInPlaceUIWindow *pDoc)
{
return S_FALSE;
}

STDMETHODIMP CExplorerHelper::HideUI( void)
{
return E_NOTIMPL;
}

STDMETHODIMP CExplorerHelper::UpdateUI( void)
{
return E_NOTIMPL;
}

STDMETHODIMP CExplorerHelper::EnableModeless(
/* [in] */ BOOL fEnable)
{
return E_NOTIMPL;
}

STDMETHODIMP CExplorerHelper::OnDocWindowActivate(
/* [in] */ BOOL fActivate)
{
return E_NOTIMPL;
}

STDMETHODIMP CExplorerHelper::OnFrameWindowActivate(
/* [in] */ BOOL fActivate)
{
return E_NOTIMPL;
}

STDMETHODIMP CExplorerHelper::ResizeBorder(
/* [in] */ LPCRECT prcBorder,
/* [in] */ IOleInPlaceUIWindow *pUIWindow,
/* [in] */ BOOL fRameWindow)
{
return E_NOTIMPL;
}
STDMETHODIMP CExplorerHelper::TranslateAccelerator(
/* [in] */ LPMSG lpMsg,
/* [in] */ const GUID *pguidCmdGroup,
/* [in] */ DWORD nCmdID)
{
return E_NOTIMPL;
}

STDMETHODIMP CExplorerHelper::GetOptionKeyPath(
/* [out] */ LPOLESTR *pchKey,
/* [in] */ DWORD dw)
{
return E_NOTIMPL;
}

STDMETHODIMP CExplorerHelper::GetDropTarget(
/* [in] */ IDropTarget *pDropTarget,
/* [out] */ IDropTarget * *ppDropTarget)
{
return E_NOTIMPL;
}

STDMETHODIMP CExplorerHelper::GetExternal(
/* [out] */ IDispatch **ppDispatch)
{
*ppDispatch = NULL;
return E_NOTIMPL;
}

STDMETHODIMP CExplorerHelper::TranslateUrl(
/* [in] */ DWORD dwTranslate,
/* [in] */ OLECHAR *pchURLIn,
/* [out] */ OLECHAR * *ppchURLOut)
{
return S_FALSE ;
}

STDMETHODIMP CExplorerHelper::FilterDataObject(
/* [in] */ IDataObject *pDO,
/* [out] */ IDataObject * *ppDORet)
{
*ppDORet = NULL;
return S_FALSE;
}


Any Help is appreciated.

Jeffrey Rich


New Programmer

unread,
Oct 11, 2002, 12:53:13 AM10/11/02
to
Jeffery,

To prevent script errors from showing, I had to override
IOleCommandTarget::Exec. The nCmdID arguement will be set to
OLECMDID_SHOWSCRIPTERROR. Here's an MFC implementation. Messy with lot's
of stuff commented but it should give you a clue..... I worked on this for
days. I don't take credit for the code and I forgot where I found it. I
think somewhere in MSDN. Good luck.

Steve


BEGIN_INTERFACE_PART(OleCommandTarget, IOleCommandTarget)
STDMETHOD(QueryStatus)(const GUID*, ULONG, OLECMD*, OLECMDTEXT*);
STDMETHOD(Exec)(const GUID*, DWORD, DWORD, VARIANTARG*, VARIANTARG*);
END_INTERFACE_PART(OleCommandTarget)

STDMETHODIMP CSupremeControlSite::XOleCommandTarget::Exec(const GUID*
pguidCmdGroup,
DWORD nCmdID,
DWORD nCmdexecopt,
VARIANTARG* pvaIn,
VARIANTARG* pvaOut )
{
METHOD_PROLOGUE_EX_(CSupremeControlSite, OleCommandTarget)

HRESULT hr = S_OK;
if (pguidCmdGroup && IsEqualGUID(*pguidCmdGroup,
CGID_DocHostCommandHandler))
{
switch (nCmdID)
{
case OLECMDID_SHOWSCRIPTERROR:
{
IHTMLDocument2* pDoc = NULL;
IHTMLWindow2* pWindow = NULL;
IHTMLEventObj* pEventObj = NULL;
BSTR rgwszNames[5] =
{
SysAllocString(L"errorLine"),
SysAllocString(L"errorCharacter"),
SysAllocString(L"errorCode"),
SysAllocString(L"errorMessage"),
SysAllocString(L"errorUrl")
};
DISPID rgDispIDs[5];
VARIANT rgvaEventInfo[5];
DISPPARAMS params;
BOOL fContinueRunningScripts = true;
int i;
params.cArgs = 0;
params.cNamedArgs = 0;

// Get the document that is currently being viewed.
hr = pvaIn->punkVal->QueryInterface(IID_IHTMLDocument2, (void **)
&pDoc);

// Get document.parentWindow.
hr = pDoc->get_parentWindow(&pWindow);
pDoc->Release();

// Get the window.event object.
hr = pWindow->get_event(&pEventObj);

// Get the error info from the window.event object.
for (i = 0; i < 5; i++)
{
// Get the property's dispID.
hr = pEventObj->GetIDsOfNames(IID_NULL, &rgwszNames[i], 1,
LOCALE_SYSTEM_DEFAULT, &rgDispIDs[i]);

// Get the value of the property.
hr = pEventObj->Invoke(rgDispIDs[i], IID_NULL,LOCALE_SYSTEM_DEFAULT,
DISPATCH_PROPERTYGET, &params, &rgvaEventInfo[i],NULL, NULL);

SysFreeString(rgwszNames[i]);
}

// At this point, you would normally alert the user with
// the information about the error, which is now contained
// in rgvaEventInfo[]. Or, you could just exit silently.
(*pvaOut).vt = VT_BOOL;

//if (fContinueRunningScripts)
//{
// Continue running scripts on the page.
(*pvaOut).boolVal = VARIANT_TRUE;
//}
//else
//{
// Stop running scripts on the page.
// (*pvaOut).boolVal = VARIANT_FALSE;
//}
break;
}
case OLECMDID_SHOWMESSAGE:
//(*pvaOut).boolVal = VARIANT_TRUE;
break;

default:
hr = OLECMDERR_E_NOTSUPPORTED;
break;
}
}
else
{
hr = OLECMDERR_E_UNKNOWNGROUP;
}
return (hr);
}

"Jeffrey Rich" <jmr...@knology.net> wrote in message
news:uqc35bq...@corp.supernews.com...

Ehsan Akhgari

unread,
Oct 11, 2002, 4:28:49 AM10/11/02
to
> My problem in a nutshell is that I am implementing IDocHostUIHandler on a
> BHO and using ICustomDoc interface to set the UIHandler in the
> OnNavigateComplete2 event of DWebBrowserEvents2. If I call the
> SetUIHandler, I will get Internet Explorer Script Error popups regardless
of
> whether I have disable script debugging check on the <Tools<Internet
> Options<Advanced Tab. However if I comment out the line I no longer get
the
> popups.

I do the same thing successfully by listening on onreadystatechange events,
and waiting until the ready state becomes "complete", and *then* using
ICustomDoc to set my UI handler. I do this from an ActiveX component hosted
by the page using an <object> tag, but this should work as well for a BHO.

BTW, the IDocHostUIHandler implementation you provided in your message is
not friendly to the default browser's implementation. You should store a
pointer to the browser's default IDocHostUIHandler, and call that
interface's version of the functions you're not interested in, and do not
implement (instead of returning E_NOTIMPL).

HTH,
--

Ehsan Akhgari

List Owner: MSVC@*NOSPAMWANTED*BeginThread.com

[Email: ehsan@*NOSPAMWANTED*beginthread.com]
[WWW: http://www.beginthread.com/Ehsan ]

Jeffrey Rich

unread,
Oct 11, 2002, 7:16:40 PM10/11/02
to
>
> I do the same thing successfully by listening on onreadystatechange
events,
> and waiting until the ready state becomes "complete", and *then* using
> ICustomDoc to set my UI handler. I do this from an ActiveX component
hosted
> by the page using an <object> tag, but this should work as well for a BHO.
>
I do not currently implement HTMLDocumentEvents which has the
OnReadyStateChanged event. When should I connect it during the
DocumentComplete event?

> BTW, the IDocHostUIHandler implementation you provided in your message is
> not friendly to the default browser's implementation. You should store a
> pointer to the browser's default IDocHostUIHandler, and call that
> interface's version of the functions you're not interested in, and do not
> implement (instead of returning E_NOTIMPL).

It was my understanding from the documentation that if I return S_FALSE or
E_NOTIMPL from IDocHostUIHandler, then that MSHTML does the default
implementation. I may be mistaken.

Thanks,

Jeffrey

Ehsan Akhgari

unread,
Oct 12, 2002, 1:01:55 AM10/12/02
to
> I do not currently implement HTMLDocumentEvents which has the
> OnReadyStateChanged event. When should I connect it during the
> DocumentComplete event?

Here is what I do. When my object is initialized (inside my
IObjectWithSite::SetSite( ) implementation) I check the ready state property
of the document object using IHTMLDocument2::get_readyState( ). If it
equals "complete", then I immediately QueryInterface( ) the document for
ICustomDoc, and set the UI handler. If not, I sink the
DISPID_HTMLDOCUMENTEVENTS_ONREADYSTATECHANGE event of HTMLDocumentEvents,
and each time my handler is invoked, I again check the ready state property
of the document like above, until I get "complete", which is when I unadvise
the sink, and use ICustomDoc to set my UI handler.

> It was my understanding from the documentation that if I return S_FALSE or
> E_NOTIMPL from IDocHostUIHandler, then that MSHTML does the default
> implementation. I may be mistaken.

Yes, but IE does implement IDocHostUIHandler, so for some of the functions
it might be doing something different that MSHTML's default. Besides, the
user may have installed another BHO, or the page may host another COM
object, which rely on implementation of IDocHostUIHandler (for example they
replace it as well), and if you don't delegate the function calls you're not
interested in to the default implementation, you're likely to break the
behavior of another application (which may be IE itself).

Jeffrey Rich

unread,
Oct 15, 2002, 11:01:39 PM10/15/02
to
Thanks for the help. I was able to solve my problem by changing where I was
returning E_NOTIMPL in methods of IDocHostUIHandler to return S_FALSE.
Specifically, I changed ShowUI to return S_FALSE.


Jeffrey Rich

unread,
Oct 17, 2002, 8:49:32 AM10/17/02
to
Sorry for the misinformation. Just changing return values to S_FALSE did
not fix my problem. I also tried the method of waiting to set the
IDocHostUIHandler until after the onreadystatechange event of
HTMLDocumentEvents has fired and is "complete". This did not work either.
I get the same results as before.

Thanks,

Jeffrey


"Jeffrey Rich" <jmr...@knology.net> wrote in message

news:uqpl9gn...@corp.supernews.com...

Ehsan Akhgari

unread,
Oct 18, 2002, 1:23:47 AM10/18/02
to
> Sorry for the misinformation. Just changing return values to S_FALSE did
> not fix my problem. I also tried the method of waiting to set the
> IDocHostUIHandler until after the onreadystatechange event of
> HTMLDocumentEvents has fired and is "complete". This did not work either.
> I get the same results as before.

Does the error pop up just when you call SetUIHandler( )? What exactly the
error is? What version(s) of IE you have tried this on? Do you redirect
calls you don't handle to the web browser's default IDocHostUIHandler? Do
you happen to have another application installed which might have a BHO?
Can you run the same code from within a COM object hosted within the page?

Jeffrey Rich

unread,
Oct 18, 2002, 8:04:50 PM10/18/02
to
> Does the error pop up just when you call SetUIHandler( )?
The problem is not that I have an error occuring. I have the errors
regardless of whether I run SetUIHandler or not. The problem is that I
don't want to get the popup message since I have set disable script debuging
in <Tools<Internet Options<Advanced.

The error is caused because some pages try to access popup windows that they
create, but I am not allowing popup windows.


> What version(s) of IE you have tried this on?

IE 6.0 on Win 98


>Do you redirect
> calls you don't handle to the web browser's default IDocHostUIHandler?

No, I am not sure how to get to IE's IDocHostUIHandler. What object should
I QueryInterface for this.


< Do
> you happen to have another application installed which might have a BHO?

I do not have any other BHO's installed.


> Can you run the same code from within a COM object hosted within the page?

Not sure.


Ehsan Akhgari

unread,
Oct 19, 2002, 10:19:00 AM10/19/02
to
> > Does the error pop up just when you call SetUIHandler( )?
> The problem is not that I have an error occuring. I have the errors
> regardless of whether I run SetUIHandler or not. The problem is that I
> don't want to get the popup message since I have set disable script
debuging
> in <Tools<Internet Options<Advanced.
>
> The error is caused because some pages try to access popup windows that
they
> create, but I am not allowing popup windows.

So you want to disable error messages, yes? This has nothing to do with the
IDocHostUIHandler, of course. See below if this is the case.

> > What version(s) of IE you have tried this on?
> IE 6.0 on Win 98
> >Do you redirect
> > calls you don't handle to the web browser's default IDocHostUIHandler?
> No, I am not sure how to get to IE's IDocHostUIHandler. What object
should
> I QueryInterface for this.

You QI the document object (IHTMLDocument2) for IOleObject, call
IOleObject::GetClientSite( ) to retrieve a IOleClientSite pointer, and QI
that interface for IDocHostUIHandler.


Now if you want to disable error messages, I think you could try
IWebBrowser2::put_Silent( ). However, this may not be sufficient. You
could use IDocHostShowUI if you were the browser's host, but unfortunately
this interface can't be set from within a BHO.

Jeffrey Rich

unread,
Oct 19, 2002, 1:22:42 PM10/19/02
to
> Now if you want to disable error messages, I think you could try
> IWebBrowser2::put_Silent( ). However, this may not be sufficient. You
> could use IDocHostShowUI if you were the browser's host, but unfortunately
> this interface can't be set from within a BHO.
Actually I want to allow the user to choose the option to disable from the
IE Disable script debugging option on the Advanced tab of the
<Tools<Internet Options dialog. If I never call the SetUIHandler, there is
an exclamation mark in the left hand corner when I get an error. (No
annoying message box.) I needed to use the IDocHostUIHandler just to
overide the context menus. I really just want the behavior for this
interface that would exist if I had not called SetUIHandler for all other
functions. I got a pointer to the IDocHostUIHandler as you suggested. I
call this pointer for all methods but the ShowContextMenu. This part seems
to work. I am not sure it fixed my problem, but another problem is still
apparent. The Save-as menu is incorrect.

Thanks,


Jeffrey


Ehsan Akhgari

unread,
Oct 20, 2002, 9:23:54 AM10/20/02
to
> This part seems
> to work. I am not sure it fixed my problem, but another problem is still
> apparent. The Save-as menu is incorrect.

What exactly do you mean by 'incorrect'?

Jeffrey Rich

unread,
Oct 20, 2002, 10:20:20 PM10/20/02
to
The Save as type no longer has Web Page complete, or Web Archive, or Web
Page HTML Only. I want no changes to the Save-As dialog when I set the
IDocHostUIHandler interface. I want no changes other than how I control the
context menus.

Thanks,

Jeffrey


Ehsan Akhgari

unread,
Oct 21, 2002, 3:03:36 AM10/21/02
to

This is really weird. It does not happen for me, and I can't think of why
replacing the IDocHostUIHandler implementation would have any effect on the
Save As dialog box.

Maybe it's something else that you (or some other apps) are doing which
causes this weirdness?

Igor Tandetnik

unread,
Oct 21, 2002, 2:54:46 PM10/21/02
to
"Jeffrey Rich" <jmr...@knology.net> wrote in message
news:ur34s0p...@corp.supernews.com...

> The Save-as menu is incorrect.

This is a known problem, in the sense that I have seen it reported many
times in the newsgroups. As soon as you set IDocHostUIHandler via
ICustomDoc from inside a BHO, Save As dialog loses options in the "Save
as type" combo. The details of how IDocHostUIHandler is implemented
don't seem to matter.

I have not seen a solution to this problem, nor do I know of any KB
article acknowledging it as a bug.
--
With best wishes,
Igor Tandetnik

"For every complex problem, there is a solution that is simple, neat,
and wrong." H.L. Mencken


Jeffrey Rich

unread,
Oct 21, 2002, 9:07:41 PM10/21/02
to
I found the solution for the Save-As problem. I now implement
IOleCommandTarget. I delegate this interface to the Client Site of the
current document. I Get the Client site on the document complete event.
The way I figured this out was by seeing what interfaces was queried for
after the SetUIHandler.
Thanks to all for the help.

Jeffrey


Jeffrey Rich

unread,
Oct 22, 2002, 10:16:37 PM10/22/02
to
It was because I was not implementing the IOleCommandTarget. I now
implement it and forward my calls to the Client Site using the same
technique that you showed me for the IDocHostUIHandler. Thanks for all your
help. It has been greatly appreciated.
"Ehsan Akhgari" <Eh...@REMOVETHISTOKENbeginthread.com> wrote in message
news:eRUXkvPeCHA.2700@tkmsftngp09...

Ehsan Akhgari

unread,
Oct 23, 2002, 6:34:50 AM10/23/02
to
> It was because I was not implementing the IOleCommandTarget. I now
> implement it and forward my calls to the Client Site using the same
> technique that you showed me for the IDocHostUIHandler. Thanks for all
your
> help. It has been greatly appreciated.

I'm glad I could help, and grateful that you shared this valuable
information here. Thanks!

0 new messages