Re: Default Implementation for IUnknown
Yes you can. Something like this:
No
What do you mean, no? Have you tried my code, and found it lacking? What
specifically seems to be the problem?
I'm sorry, I was about to type "now" but somehow forgot the "w".
Anyway, you were right that I was mixing your solutions with
Alexander's somehow. Now, I'm sticking to yours as well and have the
folloing event sink:
class ATL_NO_VTABLE DOMEventHandler :
public IDispEventImpl<1, DOMEventHandler, &DIID_HTMLElementEvents2,
&LIBID_MSHTML, 1, 1> {
typedef IDispEventImpl<1, DOMEventHandler, &DIID_HTMLElementEvents2,
&LIBID_MSHTML, 1, 1> BaseClass;
protected:
long m_dwRef;
public:
DOMEventHandler(void) {}
virtual ~DOMEventHandler(void) {}
void STDMETHODCALLTYPE OnClick(IHTMLEventObj *pEvtObj);
BEGIN_SINK_MAP(DOMEventHandler)
SINK_ENTRY_EX(1, DIID_HTMLElementEvents2,
DISPID_HTMLELEMENTEVENTS2_ONCLICK, OnClick)
END_SINK_MAP()
IDispatch* GetIDispatch() {
return
reinterpret_cast<IDispatch*>(static_cast<BaseClass*>(this));
}
};
Then I tried to attach the sink to an HTML element:
VARIANT v;
CComPtr<IHTMLElement> spElement; // assume we have for example a div
element attached here
DOMEventHandler* pDEH = new DOMEventHandler();
v.vt = VT_DISPATCH;
v.pdispVal = pDEH->GetIDispatch();
hr = spElement->put_onclick(v); // ***
CHECK_OK(hr);
Unfortunately, this is not working, I get a read access violation at
the line marked with ***. Do you have an idea what the problem could
be here?
Thanks a lot for your help!
Cheers,
Stefan