Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
inet
active_desktop
active_scrptng
asp.components
asp.db
asp.general
comctl32
comp.packaging
components.dev
dbweb
dhtml_editing
docobjects
html_authoring
html_objmodel
iis
iis.ftp
iis.security
iis.smtp_nntp
indexserver
misc
mshtml_hosting
scripting.jscript
scripting.vbscript
sdk_setup
shell_objmodel
urlmonikers
webbrowser_ctl
wininet
  
 
date: Mon, 10 Mar 2008 13:22:05 -0700 (PDT),    group: microsoft.public.inetsdk.programming.webbrowser_ctl        back       


Advise DIID_HTMLElementEvents2 events   
Hi all,

I am trying to catch DIID_HTMLElementEvents2 events in a BHO. I
couldn't get the following code to work. I got E_NOINTERFACE from hr =
pCPC->FindConnectionPoint(DIID_HTMLDocumentEvents, &m_pCP); Any help
is appreciated.

STDMETHODIMP CHelloWorldBHO::SetSite(IUnknown* pUnkSite)
{
	HRESULT hr;

	// Check that this is a connectable object.
	if(pUnkSite == NULL)
	{
		if (NULL != m_pCP)
		{
			m_pCP->Unadvise(m_dwAdviseCookie);
			m_pCP = NULL;
		}
		if (NULL != m_pCP2)
		{
			m_pCP2->Unadvise(m_dwAdviseCookie2);
			m_pCP2 = NULL;
		}
		m_pSite = NULL;
		return S_OK;
	}
	else
	{
		m_pSite = pUnkSite;

		CComPtr<IConnectionPointContainer> pCPC;
	    // Check that this is a connectable object.
	    hr = m_pSite->QueryInterface(IID_IConnectionPointContainer,
(void**)&pCPC);
	    if (SUCCEEDED(hr))
	    {
	        // Find the connection point.
	        hr = pCPC->FindConnectionPoint(DIID_HTMLDocumentEvents,
&m_pCP);
	        if (SUCCEEDED(hr))
	        {
	            // Advise the connection point.
	            // pUnk is the IUnknown interface pointer for your event
sink
	            hr = m_pCP->Advise(static_cast<IDispatch*>(this),
&m_dwAdviseCookie);
	            if (FAILED(hr))
	            {
					ATLTRACE(_T("CTheBehavior::SetSite Advise failed: %8X\n"), hr);
	            }
	        }
			// Find the connection point.
	        hr = pCPC->FindConnectionPoint(DIID_HTMLElementEvents2,
&m_pCP2);
	        if (SUCCEEDED(hr))
	        {
	            // Advise the connection point.
	            // pUnk is the IUnknown interface pointer for your event
sink
	            hr = m_pCP2->Advise(static_cast<IDispatch*>(this),
&m_dwAdviseCookie2);
	            if (FAILED(hr))
	            {
					ATLTRACE(_T("CTheBehavior::SetSite Advise(2) failed: %8X\n"),
hr);
	            }
				else
				{
				}
	        }
	    }
    }
date: Mon, 10 Mar 2008 13:22:05 -0700 (PDT)   author:   unknown

Re: Advise DIID_HTMLElementEvents2 events   
myzmlm@gmail.com wrote:
> I am trying to catch DIID_HTMLElementEvents2 events in a BHO. I
> couldn't get the following code to work. I got E_NOINTERFACE from hr =
> pCPC->FindConnectionPoint(DIID_HTMLDocumentEvents, &m_pCP); Any help
> is appreciated.

You are trying to sink events from IWebBrowser2 object whose pointer you 
get in SetSite. Not being a document object nor HTML element, it doesn't 
implement HTMLDocumentEvents or HTMLElementEvents2. It does support 
DWebBrowserEvents2.

You can get the document object with IWebBrowser2::get_Document, and 
sink HTMLDocumentEvents from it. Be aware that the old document is 
destroyed and a new one is created every time the browser navigates to a 
new page. The earliest you can get to a newly created document is in 
WebBrowser's NavigateComplete2 event.
-- 
With best wishes,
    Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not 
necessarily a good idea. It is hard to be sure where they are going to 
land, and it could be dangerous sitting under them as they fly 
overhead. -- RFC 1925
date: Mon, 10 Mar 2008 16:33:48 -0400   author:   Igor Tandetnik

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us