[For Igor] IOleCommandTarget Exec Not Called

A

Arsen V.

Hi,

I have the following declaration for my IE browser band:

typedef IDispEventImpl<0, CToolBand, &DIID_DWebBrowserEvents2,
&LIBID_SHDocVw, 1, 0> SinkWebBrowserImpl;

class ATL_NO_VTABLE CToolBand :
public CComObjectRootEx<CComSingleThreadModel>,
public CComCoClass<CToolBand, &CLSID_ToolBand>,
public IOleCommandTarget,
public IDeskBand,
public IObjectWithSiteImpl<CToolBand>,
public IPersistStream,
public IInputObject,
public IDispatchImpl<IToolBand, &IID_IToolBand, &LIBID_TOOLBANDLib>,
public SinkWebBrowserImpl
{
....
}

I implement the IOleCommandTarget interface as follows:

STDMETHOD(QueryStatus)(
/*[in]*/ const GUID *pguidCmdGroup,
/*[in]*/ ULONG cCmds,
/*[in,out][size_is(cCmds)]*/ OLECMD prgCmds[],
/*[in,out]*/ OLECMDTEXT *pCmdText)
{
return S_OK;
}

STDMETHOD(Exec)(
/*[in]*/ const GUID *pguidCmdGroup,
/*[in]*/ DWORD nCmdID,
/*[in]*/ DWORD nCmdExecOpt,
/*[in]*/ VARIANTARG *pvaIn,
/*[in,out]*/ VARIANTARG *pvaOut)
{
if (nCmdID == OLECMDID_SHOWSCRIPTERROR)
{
// Cancel the error dialog from popuping up when there are javascript
errors
(*pvaOut).vt = VT_BOOL;
(*pvaOut).boolVal = VARIANT_TRUE;
}
return S_OK;
}

For some reason I never get into the Exec method ( I tried breakpoints and
tracing it). All the javascript errors are still displaying the popup. Why
is my Exec not being used? Do I need to set something to make sure that
Exec gets called?

Thanks in advance,
Arsen
 
I

Igor Tandetnik

Arsen V. said:
I implement the IOleCommandTarget interface as follows:

STDMETHOD(Exec)(
/*[in]*/ const GUID *pguidCmdGroup,
/*[in]*/ DWORD nCmdID,
/*[in]*/ DWORD nCmdExecOpt,
/*[in]*/ VARIANTARG *pvaIn,
/*[in,out]*/ VARIANTARG *pvaOut)
{
if (nCmdID == OLECMDID_SHOWSCRIPTERROR)
{
// Cancel the error dialog from popuping up when there are
javascript errors
(*pvaOut).vt = VT_BOOL;
(*pvaOut).boolVal = VARIANT_TRUE;
}
return S_OK;
}

For some reason I never get into the Exec method ( I tried
breakpoints and tracing it).

So, you are probably following KB Article KB261003 "HOWTO: Handle Script
Errors as a WebBrowser Control Host". You know, the one that reads:

<quote>
The WebBrowser control notifies its _host_ of an unhandled script error
through the IOleCommandTarget interface.

When one of the script engines encounters an unhandled error, it
forwards the error to the WebBrowser control, which then queries its
_container_ to see if the container has implemented IOleCommandTarget.
</quote>

(emphasis mine). Now, your component is not hosting a WebBrowser control
as far as I can tell. Why again do you expect your method to be called?
--
With best wishes,
Igor Tandetnik

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

Arsen V.

Hi Igor,

I see. Is there a way for me to "pretend" to be hosting the WebBrowser so
that it notifies me through the Exec command?

Thanks,
Arsen
 
I

Igor Tandetnik

Arsen V. said:
Hi Igor,

I see. Is there a way for me to "pretend" to be hosting the
WebBrowser so that it notifies me through the Exec command?

None that I know of.
--
With best wishes,
Igor Tandetnik

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top