Click here to Skip to main content
15,892,697 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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;

    // Check that this is a connectable object.
    hr = pElem->QueryInterface(IID_IConnectionPointContainer, (void**)&pCPC);

    if (SUCCEEDED(hr))
    {
        // Find the connection point.
        hr = pCPC->FindConnectionPoint(DIID_HTMLElementEvents2, &pCP);

        if (SUCCEEDED(hr))
        {
            // Advise the connection point.
            // pUnk is the IUnknown interface pointer for your event sink
            hr = pCP->Advise(pUnk, &dwCookie);

            if (SUCCEEDED(hr))
            {
                // Successfully advised
            }

            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:

C++
hr = pElemDisp->QueryInterface(IID_IHTMLElement, (void**)&pElem);


Can anyone offer suggestions about further debugging steps?

Thank you.
Posted
Updated 1-Nov-10 3:44am
v3
Comments
Henry Minute 1-Nov-10 9:42am    
It might help if you edited your question to state what the error is.
[no name] 1-Nov-10 11:19am    
My apologies if I wasn't clear.

Executing the statement :
hr = pElemDisp->QueryInterface(IID_IHTMLElement, (void**)&pElem);

results in the value 0x80040200 being assigned to hr. Searching the 'net does not give me any specific MFC information, but ATL pages indicate that there is no connection points of that type (DIID_HTMLElementEvents2) for the retreived connection point container.

1 solution

SOLVED.

Found an implementation at:

http://dev.mingliang.org/article/chtmlview-link-click.php

This implementation has quite a different approach, simpler, more elegant. And the documentation around the code is correct and complete, unlike the other implementation pages that I was reading.

Built that code into my solution and it worked first time.

I hope this helps someone else to avoid days of wasted effort!

Regards,
Gord
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900