I am writing an MFC application that subclasses CHtmlView. I want to be able to handle mouse clicks events from buttons in the browser control.
I have implemented the code from this URL:
http://msdn.microsoft.com/en-us/library/bb508508.aspx
(titled: Handling HTML Element Events)
At runtime, an error is thrown from this code:
void CMyClass::ConnectEvents(IHTMLElement* pElem)
{
HRESULT hr;
IConnectionPointContainer* pCPC = NULL;
IConnectionPoint* pCP = NULL;
DWORD dwCookie;
hr = pElem->QueryInterface(IID_IConnectionPointContainer, (void**)&pCPC);
if (SUCCEEDED(hr))
{
hr = pCPC->FindConnectionPoint(DIID_HTMLElementEvents2, &pCP);
if (SUCCEEDED(hr))
{
hr = pCP->Advise(pUnk, &dwCookie);
if (SUCCEEDED(hr))
{
}
pCP->Release();
}
pCPC->Release();
}
}
The error occurs when executing the FindConnectionPoint statement.
I have verified that the HTML element is being found and the IHTMLElement pointer is being set properly in the calling method by:
hr = pElemDisp->QueryInterface(IID_IHTMLElement, (void**)&pElem);
Can anyone offer suggestions about further debugging steps?
Thank you.