Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problem catching OnClick event using HTMLDocumentEvents2 in a BHO

Tags:

c++

dom

com

atl

bho

I am running a BHO and i am trying to catch OnClick events using HTMLDocumentEvents2 however, the events never seem to reach the handler

this is what i am doing:

class ATL_NO_VTABLE CBlastBhoBHO :
  public CComObjectRootEx<CComSingleThreadModel>,
  public CComCoClass<CBlastBhoBHO, &CLSID_BlastBhoBHO>,
  public IObjectWithSiteImpl<CBlastBhoBHO>,
  public IDispatchImpl<IBlastBhoBHO, &IID_IBlastBhoBHO, &LIBID_BlastBhoLib, /*wMajor     =*/ 1, /*wMinor =*/ 0>,
  public IDispEventImpl<0, CBlastBhoBHO, &DIID_HTMLDocumentEvents2, &LIBID_MSHTML, 1, 0>,
  public IDispEventImpl<1, CBlastBhoBHO, &DIID_DWebBrowserEvents2, &LIBID_SHDocVw, 1, 1>



BEGIN_SINK_MAP(CBlastBhoBHO)
SINK_ENTRY_EX(0, DIID_HTMLDocumentEvents2, DISPID_HTMLDOCUMENTEVENTS2_ONCLICK,   OnClickTrigger)
SINK_ENTRY_EX(1, DIID_DWebBrowserEvents2, DISPID_DOCUMENTCOMPLETE,      OnDocumentComplete)
END_SINK_MAP()


// Handlers
void STDMETHODCALLTYPE CBlastBhoBHO::OnDocumentComplete( IDispatch *pDisp, VARIANT *url) { // works fine }
void STDMETHODCALLTYPE CBlastBhoBHO::OnClickTrigger(IHTMLEventObj *pEvtObj) { // Never called }

// From SetSite()
  ATL::IDispEventSimpleImpl<1,CBlastBhoBHO,&DIID_DWebBrowserEvents2>::DispEventAdvise(m_spWebBrowser); 


// From OnDocumentComplete
 CComQIPtr<IHTMLDocument3> doc_;
m_spWebBrowser->get_Document((IDispatch**) &doc_);
ATL::IDispEventSimpleImpl<0,CBlastBhoBHO,&DIID_HTMLDocumentEvents2>::DispEventAdvise(doc_);

I have tried several variations(using HTMLElementEvents2 etc) or Advising on different objects or Advising on the document from SetSite. my handler is never called.

Any help would be much appreciated. all i need is the onClick event.

like image 324
Yonatan Avatar asked Nov 14 '22 10:11

Yonatan


1 Answers

Probably because of the version mismatch of the LIBID_MSHTML, try change it to version 4.0, i.e. change all

IDispEventImpl<0, CBlastBhoBHO, &DIID_HTMLDocumentEvents2, &LIBID_MSHTML, 1, 0>

to

IDispEventImpl<0, CBlastBhoBHO, &DIID_HTMLDocumentEvents2, &LIBID_MSHTML, 4, 0>

like image 198
user350954 Avatar answered Dec 14 '22 22:12

user350954