Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 296123
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T06:31:11+00:00 2026-05-12T06:31:11+00:00

From the msdn website void CMyClass::ConnectEvents(IHTMLElement* pElem) { HRESULT hr; IConnectionPointContainer* pCPC = NULL;

  • 0

From the msdn website

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();
    }
} 

How do I get the pUnk pointer? I have defined CComObject *pUnk as a global variable and initialize it as CComObject::CreateInstance(&pUnk); I then use thus defined pUnk in the code above which gives the following errors:

Error 1 error C2065: ‘m_dwRef’ : undeclared identifier c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\atlcom.h 2575

Error 2 error C3861: ‘FinalRelease’: identifier not found c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\atlcom.h 2576

WHat would be the correct way to get pUnk?
A Sample code would be highly useful.
Thanks!

[Edit: I’m trying to use this sample code in my IE extension application that uses ATL to handle HTMLElementEvents2. My class derives from IDispEventImpl to handle Web browser events and I’m trying to derive from another instance of IDispEventImpl to handle HTMLElementEvents2

class ATL_NO_VTABLE CMyClass:
    public CComObjectRootEx<CComSingleThreadModel>,
    public CComCoClass<CSecurMailBHO, &CLSID_MyClass>,
    public IObjectWithSiteImpl<CMyClass>,
    public IDispatchImpl<ISecurMailBHO, &IID_IMyClass, &LIBID_MyClassLib, /*wMajor =*/ 1, /*wMinor =*/ 0>,
    public IDispEventImpl<1, CMyClass, &DIID_DWebBrowserEvents2, &LIBID_SHDocVw, 1, 1>, //Safe alternative to Invoke
    public IDispEventImpl<2, CMyClass, &DIID_HTMLElementEvents2, &LIBID_MSHTML, 4, 0>
{
.
.
.
BEGIN_SINK_MAP(CMyClass)
     SINK_ENTRY_EX(1, DIID_DWebBrowserEvents2, DISPID_DOCUMENTCOMPLETE, OnDocumentComplete)//Do stuff OnDocumentComplete
     SINK_ENTRY_EX(1, DIID_DWebBrowserEvents2, DISPID_BEFORENAVIGATE2, BeforeNavigate2)//Handle BeforeNavigate2

     SINK_ENTRY_EX(2, DIID_HTMLElementEvents2, DISPID_HTMLELEMENTEVENTS2_ONSCROLL, OnScroll)//Handle OnScroll Event

END_SINK_MAP()
.
.

}

In my OnDocumentComplete, I call IWebBrowser2::get_Document followed by IHTMLDocument2::get_body to get the IHTMLElement object body. This is what’s being sent to ConnectEvents function above. But so far, no luck. I don’t know what the pUnk pointer is, and further, it seems that the call to FindConnectionPoint fails, i.e, there is no HTMLElementEvents2 connection point in the point container. Any ideas as to how I should go on about handling the htmlelementevents?????????

End Edit]

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T06:31:12+00:00Added an answer on May 12, 2026 at 6:31 am

    ATLEventHandling Sample

    Edit:

    void CMyClass::ConnectEvents(IHTMLElement* pElem)
    {
        typedef IDispEventImpl<2, CMyClass, DIID_HTMLElementEvents2, LIBID_MSHTML, 4, 0> IMyClassHTMLElementEvents2Sink;
        IMyClassHTMLElementEvents2Sink::DispEventAdvise(pElem);
    }
    

    Because you have multiple functions DispEventAdvise on the the base IDispEventImpl classes.

    Also it seems earliest version of MSHTML that defines HTMLElementEvents2 is 5.0.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am attempting to pull some information from my tnsnames file using regex. I
I would like to get a sum from a column, with and without a
If all tables I want to delete from have the column gamer_id can i
I'm in the process of porting some code from Linux to Mac OS X.
I have a new web app that is packaged as a WAR as part
I have several USB mass storage flash drives connected to a Ubuntu Linux computer
I am writing a query to fetch results for all the values in a
I was reading JavaScript: The Good Parts and the author mentions that JavaScript is
I've found several jQuery syntaxes for nullifying the enter on a form. First one:
I'm trying to build a C++ extension for python using swig. I've followed the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.