Exemple #1
0
BOOL COutlookButton::SetupConnection(IDispatch *pDisp)
{
	IConnectionPointContainer *pCPC = 0;
	HRESULT hr = S_OK;

	try
	{
		// Set up the connection and call Advise.
		if (FAILED((hr=pDisp->QueryInterface(IID_IConnectionPointContainer,(void **)&pCPC)))) 
			return FALSE;

		if (FAILED((hr=pCPC->FindConnectionPoint(__uuidof(Office::_CommandBarButtonEvents),&m_pCP)))) 
		{
			pCPC->Release();
			return FALSE;
		}
		if (FAILED((hr=m_pCP->Advise(static_cast<IDispatch*>(this), &m_dwCookie)))) 
		{
			pCPC->Release();
			return FALSE;
		}

		pCPC->Release();
	}
	catch(...)
	{
	}
	return TRUE;
}
Exemple #2
0
void CInviteChatDlg::InitMpaWebEvent()
{
	IConnectionPointContainer* pCPContainer = NULL;
	CComPtr<IConnectionPoint>  m_pSessionConnectionPoint;
	HRESULT hr = m_pWebCustomizer->QueryInterface(IID_IConnectionPointContainer,(void**)&pCPContainer);
	
	if (pCPContainer)
	{
		hr = pCPContainer->FindConnectionPoint(__uuidof(_IMpaWebCustomizerEvents),&m_pSessionConnectionPoint);
		if(SUCCEEDED(hr))
		{
			LPUNKNOWN pInterEvent = GetInterface(&IID_IUnknown);
			hr = m_pSessionConnectionPoint->Advise(pInterEvent ,&m_dwSessionCookie);
			pCPContainer->Release();
		}
		else
		{
			ASSERT(FALSE);
		}
	}
	else
	{
		ASSERT(FALSE);
	}
}
Exemple #3
0
QWmpEvents::QWmpEvents(IUnknown *source, QObject *parent)
    : QObject(parent)
    , m_ref(1)
    , m_connectionPoint(0)
    , m_adviseCookie(0)
{
    HRESULT hr;
    IConnectionPointContainer *container = 0;

    if ((hr = source->QueryInterface(
            IID_IConnectionPointContainer, reinterpret_cast<void **>(&container))) != S_OK) {
        qWarning("No connection point container, %x: %d", hr, qwmp_error_string(hr));
    } else {
        if ((hr = container->FindConnectionPoint(
                __uuidof(IWMPEvents), &m_connectionPoint)) != S_OK) {
            qWarning("No connection point for IWMPEvents %d", hr);
        } else if ((hr = m_connectionPoint->Advise(
                static_cast<IWMPEvents3 *>(this), &m_adviseCookie)) != S_OK) {
            qWarning("Failed to link to connection point, %x, %s", hr, qwmp_error_string(hr));

            m_connectionPoint->Release();
            m_connectionPoint = 0;
        }
        container->Release();
    }
}
Exemple #4
0
void mHpWebClient::AddSink() {
  TraceFunc("mHpWebClient::AddSink");
  IConnectionPointContainer* cpc;
  IConnectionPoint*          cp;

  if (!browserObject_) {
    ::MessageBox(0, "browserObject_ is null in AddSink", 0, 0);
    return;
  }
  if (browserObject_->QueryInterface(IID_IConnectionPointContainer, reinterpret_cast<void**>(&cpc)) == S_OK) {
    if (cpc->FindConnectionPoint(DIID_DWebBrowserEvents2, &cp) == S_OK) {

      // TODO: Member Var
      unsigned long cookie = 1;
      if (! (SUCCEEDED(cp->Advise(static_cast<IDispatch*>(this), &cookie)) ) ) {
        ::MessageBox(0, "Advise failed", 0, 0);
      }
    }
    else {
      ::MessageBox(0, "FindConnectionPoint", 0, 0);
    }
  }
  else {
    ::MessageBox(0, "QueryInterface for IID_IConnectionPointContainer", 0, 0);
  }
}
HRESULT CLoopbackDevice::SetupConnectionPoint(IUnknown* punkObject,
                                              REFIID iidConnectionPoint) {
  HRESULT hr = S_OK;
  IConnectionPointContainer* piConnectionPointContainer = NULL;
  IUnknown* punkSink = NULL;

  //If there is already connection point enabled, disable it
  if(NULL != m_piConnectionPoint) {
    IfFailHrGo(ReleaseConnectionPoint());
  }
        
  IfFailHrGo(punkObject->QueryInterface(IID_IConnectionPointContainer,
                                        reinterpret_cast<void **>(&piConnectionPointContainer)));

  IfFailHrGo(piConnectionPointContainer->FindConnectionPoint(iidConnectionPoint,
                                                             &m_piConnectionPoint));

  // Get the IUknown of this interface as this is the event sink
  punkSink = (this)->GetUnknown(); 

  if(NULL == punkSink) {
    IfFailHrGo(E_UNEXPECTED);
  }

  IfFailHrGo(m_piConnectionPoint->Advise(punkSink, &m_dwConnectionCookie));


Exit:
  return hr;
}
Exemple #6
0
BOOL
ZDrOleClient::InterfaceDisconnect( IUnknown *pObj, REFIID riid,
                                   LPDWORD pdwConn )
{
   HRESULT                   hr;
   IConnectionPointContainer *pCPointContainer = 0;
   IConnectionPoint          *pCPoint = 0;

   if ( pObj == 0 || pdwConn == 0 )
      return( FALSE );

   if ( *pdwConn == 0 )
      return( FALSE );

   hr = pObj->QueryInterface( IID_IConnectionPointContainer,
                              (LPVOID *) &pCPointContainer );
   if ( FAILED( hr ) )
      return( FALSE );

   hr = pCPointContainer->FindConnectionPoint( riid, &pCPoint );
   if ( SUCCEEDED( hr ) )
   {
      // This is the Point to kill m_pEditorEventSink. We are doing this
      // through Unadvise
      hr = pCPoint->Unadvise(*pdwConn);
      if ( SUCCEEDED( hr ) )
         *pdwConn = 0L;

      pCPoint->Release( );
   }

   pCPointContainer->Release( );
   return( SUCCEEDED( hr ) );
} // InterfaceDisconnect
Exemple #7
0
void CCoolInet2::CloseEventContainer()
{
	IConnectionPointContainer* pCPContainer = NULL;
	IConnectionPointPtr  m_pSessionConnectionPoint;
	p_InetSession->QueryInterface(IID_IConnectionPointContainer,(void**)&pCPContainer);
	
	if (pCPContainer)
	{
		HRESULT hr = pCPContainer->FindConnectionPoint(__uuidof(_ISessionEvents),&m_pSessionConnectionPoint);
		if(SUCCEEDED(hr))
		{
//			LPUNKNOWN pInterEvent = m_InetSessionEvent.GetInterface(&IID_IUnknown);
			hr = m_pSessionConnectionPoint->Unadvise(dwSessionCookie);
			pCPContainer->Release();
		}
		else
		{
			ASSERT(FALSE);
		}
	}
	else
	{
		ASSERT(FALSE);
	}
   dwSessionCookie = 0;
}
Exemple #8
0
/**********************************************************
* COperator::RegisterTapiEventInterface *
*---------------------------------------*
*   Description:
*       Get a unique identifier (m_ulAdvice) for 
*       this connection point.
*   Return:
*       S_OK
*       Failed HRESULTs from QI(), 
*           IConnectionPointContainer::FindConnectionPoint(),
*           or IConnectionPoint::Advise()
***********************************************************/
HRESULT COperator::RegisterTapiEventInterface()
{
    HRESULT                       hr = S_OK;
    IConnectionPointContainer   * pCPC;
    IConnectionPoint            * pCP;
    

    hr = m_pTapi->QueryInterface( IID_IConnectionPointContainer,
                                (void **)&pCPC );

    if ( SUCCEEDED( hr ) )
    {
        hr = pCPC->FindConnectionPoint( IID_ITTAPIEventNotification,
                                       &pCP );
        pCPC->Release();
    }
        
    if ( SUCCEEDED( hr ) )
    {
        hr = pCP->Advise( m_pTAPIEventNotification,
                          &m_ulAdvise );

        pCP->Release();
    }
    return hr;
}   /* COperator::RegisterTapiEventInterface */
Exemple #9
0
	//コネクションポイントへの接続
bool Advise(IUnknown * container, REFIID iid, IUnknown * sink, DWORD * cookie, IConnectionPoint ** pcp = NULL)
{
	IConnectionPointContainer * cpc;
	IConnectionPoint * cp;

	HRESULT result;

	if(pcp == NULL)
		pcp = &cp;

	container->QueryInterface(IID_IConnectionPointContainer, (void **)&cpc);
	if(cpc == 0)
		return false;

	cpc->FindConnectionPoint(iid, pcp);
	cpc->Release();
	if(*pcp == 0)
		return false;

	if(FAILED(result = (*pcp)->Advise(sink, cookie)))
		return false;

	if(pcp == &cp)
		cp->Release();
	return true;
}
Exemple #10
0
VOID WindCppAPIImp::release()
{
	if (m_pDWindData != NULL)
	{
		cancelAllRequest();

		HRESULT hr = E_FAIL;
		IConnectionPointContainer *pCPC;
		hr = m_pDWindData.QueryInterface(IID_IConnectionPointContainer, (void **)&pCPC);
		if(SUCCEEDED(hr))
		{
			IConnectionPoint *pCP;
			hr = pCPC->FindConnectionPoint(__uuidof(WindDataCOMLib::_DWindDataCOMEvents), &pCP);
			if (SUCCEEDED(hr))
			{
				hr = pCP->Unadvise(m_dwAdvise);
				pCP->Release();
			}
			pCPC->Release();
		}

		m_pDWindData.Release();
		m_pDWindData = NULL;
		
		if (m_pSink != NULL)
		{
			delete m_pSink;
			m_pSink = NULL;
		}

		m_dwAdvise = 0;
	}	
}
Exemple #11
0
DWORD tLuaCOM::addConnection(tLuaCOM *server)
{
  if(!server->hasTypeInfo())
    return false;

  HRESULT hr;
  IDispatch *pdisp_server = server->GetIDispatch();

  IConnectionPointContainer *pcpc = NULL;

  IConnectionPoint *connection_point;

  hr = pdisp->QueryInterface
    (
      IID_IConnectionPointContainer, (void **) &pcpc
    );

  if(FAILED(hr))
  {
    return 0;
  }

  {
    IID guid;

    server->GetIID(&guid);

    hr = pcpc->FindConnectionPoint(guid, &connection_point);
  }

  pcpc->Release();
  pcpc = NULL;

  if(FAILED(hr))
  {
    return 0;
  }

  DWORD connection_point_cookie;

  hr = connection_point->Advise
    (
      (IUnknown *) pdisp_server, &connection_point_cookie
    );

  if(FAILED(hr))
  {
    connection_point->Release();
    connection_point = NULL;

    return 0;
  }

  if(conn_point!=NULL)
	  conn_point->Release();
  conn_point = connection_point;
  conn_cookie = connection_point_cookie;

  return connection_point_cookie;
}
Exemple #12
0
void CWebWindow::Unadvise()
{
	IConnectionPointContainer* pCPContainer = NULL;
	IConnectionPointPtr  m_pSessionConnectionPoint;
	HRESULT hr = m_pWebCustomizer->QueryInterface(IID_IConnectionPointContainer,(void**)&pCPContainer);
	
	if (pCPContainer)
	{
		hr = pCPContainer->FindConnectionPoint(__uuidof(_IMpaWebCustomizerEvents),&m_pSessionConnectionPoint);
		if(SUCCEEDED(hr))
		{
			//			LPUNKNOWN pInterEvent = m_MpaWebEvent.GetInterface(&IID_IUnknown);
			//			hr = m_pSessionConnectionPoint->Advise(pInterEvent ,&m_dwSessionCookie);
			hr = m_pSessionConnectionPoint->Unadvise(m_dwSessionCookie);
			pCPContainer->Release();
		}
		else
		{
			ASSERT(FALSE);
		}
	}
	else
	{
		ASSERT(FALSE);
	}
}
// unadvise the world without decrementing the reference count of the client.
//reduces refcount of pworld by 1.
void DeleteWorld(IWorld* pWorld, DWORD dwCookie)
{
	IConnectionPoint* pconnpt = NULL;
	IConnectionPointContainer* pconnptctr = NULL;

	if (pWorld == NULL) 
		return;

	HRESULT hr = pWorld->QueryInterface(IID_IConnectionPointContainer, (LPVOID*)&pconnptctr);
	if (SUCCEEDED(hr))
	{
		hr = pconnptctr->FindConnectionPoint(IID_IVWObjectSite, &pconnpt);
		if (SUCCEEDED(hr))
		{
			// HACK: artificially addref ptr
			IUnknown* p = (IUnknown *)dwCookie;
			p->AddRef();

			pconnpt->Unadvise(dwCookie);
			pconnpt->Release();
		}
		pconnptctr->Release();
	}

	pWorld->Terminate();

	// REVIEW: let caller SAFERELEASE ptr rather than do it in here
//	SAFERELEASE(pWorld);
}
BOOL CXTPReportDataManager::DataBind()
{
    HRESULT hr = E_FAIL;
    try
    {
        if (m_pDataSource == NULL)
            return FALSE;

        m_pConnection = NULL;

        // get connection
        _variant_t vtConnection;
        if (SUCCEEDED(hr = m_pDataSource->get_ActiveConnection(&vtConnection)) && vtConnection.pdispVal)
        {
            m_pConnection = vtConnection;
        }
        // clear report control
        ClearReportControl();
        // create columns
        if (FAILED(hr = CreateColumns()))
            return FALSE;
        // create records
        if (FAILED(hr = AddReportRecords(m_pDataSource, FALSE)))
            return FALSE;
        m_pReportControl->Populate();
        // advise events
        m_pRstEvent = new CRstEvent(this);
        if (!m_pRstEvent)
            return FALSE;
        IUnknown *pUnk = NULL;
        hr = m_pRstEvent->QueryInterface(__uuidof(IUnknown), (void **) &pUnk);
        if (FAILED(hr))
            return FALSE;
        IConnectionPointContainer *pCPC = NULL;
        IConnectionPoint *pCP = NULL;
        hr = m_pDataSource->QueryInterface(__uuidof(IConnectionPointContainer), (void**)&pCPC);
        if (FAILED(hr))
            return FALSE;
        hr = pCPC->FindConnectionPoint(__uuidof(XTPREPORTADODB::RecordsetEvents), &pCP);
        pCPC->Release();
        if (FAILED(hr))
            return FALSE;
        hr = pCP->Advise(pUnk, &m_dwRstEvent);
        pCP->Release();
    }
    catch(_com_error &e)
    {
        TRACE_ProviderError(m_pConnection);
        TRACE_ComError(e);
        hr = FAILED(hr) ? hr : E_FAIL;
    }
    catch(...)
    {
        TRACE(_T("Unknown error in DataBind()\n"));
        hr = FAILED(hr) ? hr : E_FAIL;
    }

    return FAILED(hr) ? FALSE : TRUE;
}
HRESULT CSoftHIDInputKbdMapper::SetupEventSink
(
    IUnknown         *punkObject,
    IUnknown         *punkSink,
    REFIID            iidConnectionPoint,
    IConnectionPoint *&rpiConnectionPoint,
    DWORD             &rdwCookie
)
/*++

Routine Description:
    If punkObject is non-NULL installs event sink on specific
    connection point and returns IConnectionPoint and cookie.

Arguments:
    punkObject - IUnknown on object

    punkSink - IUnknown of event sink to install

    iidConnectionPoint - IID of desired connection point

    rpiConnectionPoint - connection point returned here

    rdwCookie - connection point cookie returned here

Synchronization:
    None

Return value:
    S_OK - success
    other - from called routines
--*/
{
    HRESULT                    hr = S_OK;
    IConnectionPointContainer *piConnectionPointContainer = NULL;

    rpiConnectionPoint = NULL;
    rdwCookie = 0;

    IfFalseHrGo(NULL != punkObject, S_OK);

    IfFailHrGo(punkObject->QueryInterface(IID_IConnectionPointContainer,
                                          reinterpret_cast<void **>(&piConnectionPointContainer)));

    IfFailHrGo(piConnectionPointContainer->FindConnectionPoint(iidConnectionPoint,
                                                               &rpiConnectionPoint));

    IfFailHrGo(rpiConnectionPoint->Advise(punkSink, &rdwCookie));

Exit:
    if (FAILED(hr))
    {
        RELEASE(rpiConnectionPoint);
        rdwCookie = 0;
    }
    RELEASE(piConnectionPointContainer);

    return hr;
}
// Set up the connection to a manipulation or inertia processor
BOOL CManipulationEventSink::SetupConnPt(IUnknown *manipulationProc)
{
	BOOL success = FALSE;
	IConnectionPointContainer* pConPointContainer = NULL;

	// Only connect if there isn't already an active connection
	if (m_pConnPoint == NULL)
	{
		// Check if supports connectable objects
		success = SUCCEEDED(manipulationProc->QueryInterface(IID_IConnectionPointContainer, 
			(LPVOID*)&(pConPointContainer)));

		// Get connection point interface
		if(success)
		{
			success = SUCCEEDED(pConPointContainer->FindConnectionPoint(
				_uuidof(_IManipulationEvents), 
				&(m_pConnPoint)));
		}

		// Clean up connection point container
		if (pConPointContainer != NULL)
		{
			pConPointContainer->Release();
			pConPointContainer = NULL;
		}

		// Hook event object to the connection point
		IUnknown* pUnk = NULL;
		if(success)
		{
			// Get pointer to manipulation event sink's IUnknown pointer
			success = SUCCEEDED(QueryInterface(IID_IUnknown, (LPVOID*)&pUnk));
		}

		// Establish connection point to callback interface
		if(success)
		{
			success = SUCCEEDED(m_pConnPoint->Advise(pUnk, &(m_uID)));
		}

		// Clean up IUnknown pointer
		if(pUnk != NULL)
		{
			pUnk->Release();
		}

		if (!success && m_pConnPoint != NULL)
		{
			m_pConnPoint->Release();
			m_pConnPoint = NULL;
		}
	}

	return success;
}
Exemple #17
0
BOOL
ZDrOleClient::InterfaceConnect( IUnknown *pObj, REFIID riid,
                                IUnknown *pIUnknownSink, LPDWORD pdwConn )
{
   TraceLineS( "ZDrOleClient::InterfaceConnect", "" );
   HRESULT                   hr;
   IConnectionPointContainer *pCPointContainer = 0;
   IConnectionPoint          *pCPoint = 0;

   if ( pObj == 0 || pIUnknownSink == 0 || pdwConn == 0 )
      return( FALSE );

   hr = pObj->QueryInterface( IID_IConnectionPointContainer,
                              (LPVOID *) &pCPointContainer );
   if ( FAILED( hr ) )
      return( FALSE );

   hr = pCPointContainer->FindConnectionPoint( riid, &pCPoint );
   if ( SUCCEEDED( hr ) )
   {
      hr = pCPoint->Advise( pIUnknownSink, pdwConn );
      if ( hr == E_POINTER )
         AfxMessageBox( "Invalid Pointer!" );
      else
      if ( hr == CONNECT_E_ADVISELIMIT )
         AfxMessageBox( "No more Connections available!" );
      else
      if ( hr == CONNECT_E_CANNOTCONNECT )
         AfxMessageBox( "No Connection!" );

      pCPoint->Release( );
   }
   else
   {
       if ( hr == E_OUTOFMEMORY )
          TraceLineS( "FindConnectionPoint failed: ", "E_OUTOFMEMORY" );
       else
       if ( hr == E_UNEXPECTED )
          TraceLineS( "FindConnectionPoint failed: ", "E_UNEXPECTED" );
       else
       if ( hr == E_POINTER )
          TraceLineS( "FindConnectionPoint failed: ", "E_POINTER" );
       else
       if ( hr == CONNECT_E_NOCONNECTION )
          TraceLineS( "FindConnectionPoint failed: ", "CONNECT_E_NOCONNECTION" );
       else
       if ( hr == S_OK )
          TraceLineS( "FindConnectionPoint failed: ", "S_OK" );
       else
          TraceLineX( "FindConnectionPoint failed: ", (zLONG) hr );
   }

   pCPointContainer->Release( );
   return( SUCCEEDED( hr ) );
} // InterfaceConnect
/*
** Constructor.
**
*/
PlayerITunes::CEventHandler::CEventHandler(PlayerITunes* player) :
	m_Player(player),
	m_RefCount(),
	m_ConnectionPoint(),
	m_ConnectionCookie()
{
	IConnectionPointContainer* icpc;
	m_Player->m_iTunes->QueryInterface(IID_IConnectionPointContainer, (void**)&icpc);
	icpc->FindConnectionPoint(DIID__IiTunesEvents, &m_ConnectionPoint);
	m_ConnectionPoint->Advise(this, &m_ConnectionCookie);
	icpc->Release();
}
Exemple #19
0
static void initEventHandler()
{
	IConnectionPointContainer* icpc;
	iTunes->QueryInterface(IID_IConnectionPointContainer, (void **)&icpc);
	IConnectionPoint* icp;
	icpc->FindConnectionPoint(DIID__IiTunesEvents, &icp);
	icpc->Release();
	DWORD dwAdvise;
	iTunesEventHandler = new CiTunesEventHandler();
	icp->Advise(iTunesEventHandler, &dwAdvise);
	icp->Release();
}
Exemple #20
0
BOOL WindCppAPIImp::initialize()
{
	if (m_pDWindData != NULL)
	{
		return TRUE;
	}

	HRESULT hr = E_FAIL;
	hr = m_pDWindData.CreateInstance(__uuidof(WindDataCOMLib::WindDataCOM), NULL, CLSCTX_ALL);

	if(!SUCCEEDED(hr))
	{
		return FALSE;
	}

	m_pDWindData->enableAsyn(1);

	IConnectionPointContainer *pCPC;
	hr = m_pDWindData.QueryInterface(IID_IConnectionPointContainer, (void **)&pCPC);
	if(!SUCCEEDED(hr))
	{
		return FALSE;
	}

	IConnectionPoint *pCP;
	hr = pCPC->FindConnectionPoint(__uuidof(WindDataCOMLib::_DWindDataCOMEvents), &pCP);
	if (!SUCCEEDED(hr))
	{
		return FALSE;
	}
	pCPC->Release();

	IUnknown *m_pSinkUnk;
	m_pSink = new WindDataComSink();

	hr = m_pSink->QueryInterface(IID_IUnknown, (void **)&m_pSinkUnk);
	if(!SUCCEEDED(hr))
	{
		pCP->Release();
		return FALSE;
	}

	hr = pCP->Advise(m_pSinkUnk, &m_dwAdvise);
	if(!SUCCEEDED(hr))
	{
		return FALSE;
	}
	pCP->Release();

	return TRUE;
}
Exemple #21
0
void tLuaCOM::releaseConnections() {
	if(conn_point==NULL)
		return;
	
	conn_point->Release();
	IConnectionPointContainer *pcpc;

    HRESULT hr = pdisp->QueryInterface(IID_IConnectionPointContainer, (void **) &pcpc);

    if(FAILED(hr))
    {
	    return;
    }

	IEnumConnectionPoints *pecp;

	hr = pcpc->EnumConnectionPoints(&pecp);
	pcpc->Release();

    if(FAILED(hr))
    {
	    return;
    }

	pecp->Reset();

	IConnectionPoint *pcp;
	ULONG fetched = 0;

	hr = pecp->Next(1, &pcp, &fetched);
	while(SUCCEEDED(hr) && fetched) {
		IEnumConnections *pec;
		hr = pcp->EnumConnections(&pec);
		if(SUCCEEDED(hr)) {
			pec->Reset();
			CONNECTDATA conn;
			ULONG conn_fetched = 0;
			hr = pec->Next(1, &conn, &conn_fetched);
			while(SUCCEEDED(hr) && conn_fetched) {
				pcp->Unadvise(conn.dwCookie);
				hr = pec->Next(1, &conn, &conn_fetched);
			}
			pec->Release();
		}
        pcp->Release();
  	    pecp->Next(1, &pcp, &fetched);
	}
	
	pecp->Release();
}
// Connects CManipulationEventSink object to ManipulationProcessor.
// in:
//      pManipulationProcessor - pointer to the IManipulationProcessor to connect to
// returns:
//      success status, true if the connection is established, false on failure
bool CManipulationEventSink::Connect(IManipulationProcessor* pManipulationProcessor)
{
    // Check input arguments
    if (pManipulationProcessor == NULL)
    {
        ASSERT((pManipulationProcessor != NULL) && L"CManipulationEventSink::Create : incorrect arguments");
        return false;
    }

    // Check object state
    if ((m_dwCookie != 0) || (m_pConnection != NULL))
    {
        ASSERT((m_dwCookie == 0) && (m_pConnection == NULL) && L"CManipulationEventSink::Connect : connection already established");
        return false;
    }

    // Get the container with the connection points.
    IConnectionPointContainer* pConnectionContainer = NULL;
    HRESULT hr = pManipulationProcessor->QueryInterface(&pConnectionContainer);
    if (FAILED(hr))
    {
        ASSERT(SUCCEEDED(hr) && L"CManipulationEventSink::Connect : failed to get the container with the connection points");
        return false;
    }

    // Get a connection point.
    hr = pConnectionContainer->FindConnectionPoint(__uuidof(_IManipulationEvents), &m_pConnection);
    if (FAILED(hr))
    {
        ASSERT(SUCCEEDED(hr) && L"CManipulationEventSink::Connect : failed to get a connection point");
        pConnectionContainer->Release();
        return false;
    }

    // Release the connection container.
    pConnectionContainer->Release();

    // Advise. Establishes an advisory connection between the connection point and the 
    // caller's sink object. 
    hr = m_pConnection->Advise(this, &m_dwCookie);
    if (FAILED(hr))
    {
        ASSERT(SUCCEEDED(hr) && L"CManipulationEventSink::Connect : failed to Advise");
        m_pConnection->Release();
        m_pConnection = NULL;
        return false;
    }

    return true;
}
	Win32HtmlViewRep( Win32HtmlView *view, HWND hw,int style ):hwnd(hw){

		owner=view;
		site.rep=this;
		eventsink.rep=this;
		frame.rep=this;
		
		viewstyle=style;
		emitNavEvent=!!(viewstyle & BBHtmlView::NONAVIGATE);

		currenturl=new BBString("");
		eventurl=new BBString("");

		OleCreate( CLSID_WebBrowser,IID_IOleObject,OLERENDER_DRAW,0,&site,&storage,(void**)&oleObject );

		OleSetContainedObject( oleObject,TRUE);

		oleObject->SetHostNames(L"Web Host",L"Web View");
		oleObject->QueryInterface(IID_IWebBrowser2,(void**)&iBrowser);
		oleObject->QueryInterface(IID_IOleInPlaceObject,(void**)&inPlaceObject );

		oleObject->QueryInterface(IID_IConnectionPointContainer,(void**)&iConnection);
		iConnection->FindConnectionPoint(DIID_DWebBrowserEvents, &iConnectionPoint);
		iConnectionPoint->Advise((LPUNKNOWN)&eventsink, &dwCookie);

		RECT rect;
		::GetClientRect( hwnd,&rect );
		oleObject->DoVerb(OLEIVERB_SHOW,NULL,&site,-1,hwnd,&rect);
		go( "about:blank" );
	}
HRESULT WebHelper::Init(DispatchCallback *pCallback)
{
    m_pDispatchCB = pCallback;

    IConnectionPointContainer *pCPContainer = NULL;
    HWND hwndBrowser = NULL;

    // Create the InternetExplorer object.
    HRESULT hr = CoCreateInstance(CLSID_InternetExplorer, NULL,
        CLSCTX_ALL, IID_IWebBrowser2, (void**)&m_pBrowser);
    LOG_MSG_IF_FAILED(L"CoCreateInstance(CLSID_InternetExplorer)", hr);

    // Set up the connection point so that we receive events.
    if (SUCCEEDED(hr))
    {
        hr = m_pBrowser->QueryInterface(IID_IConnectionPointContainer, (void**)&pCPContainer);
        LOG_MSG_IF_FAILED(L"QueryInterface for IConnectionPointContainer)", hr);
    }

    if (SUCCEEDED(hr))
    {
        hr = pCPContainer->FindConnectionPoint(DIID_DWebBrowserEvents2, &m_pCP);
        LOG_MSG_IF_FAILED(L"FindConnectionPoint)", hr);
    }

    if (SUCCEEDED(hr))
    {
        hr = m_pCP->Advise(this, &m_dwCookie);
        LOG_MSG_IF_FAILED(L"Advise)", hr);
    }

    if (SUCCEEDED(hr))
    {
        hr = m_pBrowser->get_HWND((SHANDLE_PTR*)&hwndBrowser);
    }

    // Move the browser window to the front.
    if (SUCCEEDED(hr))
    {
        SetWindowPos(hwndBrowser, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
    }

    SAFE_RELEASE(pCPContainer);

    return hr;
}
Exemple #25
0
/******************************************************************
 * CHandler::SinkEvents()
 *
 *    Sets up the Click event sink and saves a pointer to the 
 *    IConnectionPoint for the button. The sink should be freed before
 *    the application is released.
 *
 ******************************************************************/
HRESULT CHandler::SinkEvents(LPDISPATCH pObject)
{
    HRESULT hr;

 // Get server's IConnectionPointContainer interface.
    IConnectionPointContainer* pCPC;
    hr = pObject->QueryInterface(IID_IConnectionPointContainer, (void **)&pCPC);
    if (SUCCEEDED(hr)) {

    // Find connection point for events we're interested in.
        hr = pCPC->FindConnectionPoint(m_riid, &m_pConnection);
        if (SUCCEEDED(hr)) {
            hr = m_pConnection->Advise(static_cast<IDispatch*>(this), &m_dwCookie);
        }
    // Release the IConnectionPointContainer
        pCPC->Release();
    }
    return hr;
}
/////////////////////////////////////////////////////////////////////
// Initialize function
HRESULT COPCGroupImpl::Initialize( COPCAutoServer* pParent,
                                   IUnknown* pUnk )
{
   if(pUnk == NULL)
      return E_INVALIDARG;

   HRESULT hr=S_OK;

   m_pParent = pParent;
   ((COPCAutoServerObject*)m_pParent)->AddRef();
   m_pOPCGroup = pUnk;  // get a group interface pointer

   if( !m_pOPCGroup )
      return E_FAIL;    // get QI error

   // get initial values for state variables
   LPWSTR name;
   OPCHANDLE   localclient;
   hr = m_pOPCGroup->GetState( &m_rate, &m_active, &name, &m_timebias,
                               &m_deadband, &m_LCID, &localclient, &m_server );
   if( SUCCEEDED(hr) )
   {
      m_name = name;
      CoTaskMemFree( name );
   }
   else
   {
      m_rate = 0;
      m_active = TRUE;
   }
   _ASSERTE(m_client == (OPCHANDLE)this);

   // See if this server supports OPC 2.0 ConnectionPoints
   IConnectionPointContainer *pCPC = 0;
   HRESULT hrCP = m_pOPCGroup->QueryInterface(IID_IConnectionPointContainer, (void**)&pCPC);
   if( SUCCEEDED(hrCP) )
   {
      m_usingCP = TRUE;  // This server supports 2.0
      pCPC->Release();
   }

   return hr;
}
Exemple #27
0
void EnumConnectionPoint(IDispatch *pDisp, LPCSTR comment)
{
	if (!pDisp) return;
	HRESULT hr = S_OK;

	USES_CONVERSION;
	IConnectionPointContainer *spCPC = NULL;
	IConnectionPoint *spCP = NULL;
	IEnumConnectionPoints *ppEnum = NULL;
	IID id;
	LPOLESTR strGUID = 0;
	CComBSTR bstrId = NULL;

	if(comment) cout << comment << _T(" ");
	cout << _T("ConnectionPoint: [");
	hr = pDisp->QueryInterface(IID_IConnectionPointContainer, reinterpret_cast<void**>(&spCPC));
	if (SUCCEEDED(hr) && spCPC)
	{
		hr = spCPC->EnumConnectionPoints(&ppEnum);
		while(SUCCEEDED(ppEnum->Next(1, &spCP, NULL)) && spCP) 
		{
			spCP->GetConnectionInterface(&id);
			// 注意此处StringFromIID的正确用法, 否则会在Debug状态下出错: user breakpoint called from code 0x7c901230
			StringFromIID(id, &strGUID);
			bstrId = strGUID;
			CoTaskMemFree(strGUID);
			cout << (bstrId ? OLE2CT(bstrId) : _T("")) << _T(", ");
		}
	}
	cout << "]" << endl;
	if(spCP) spCP->Release();
	if(ppEnum) ppEnum->Release();
	if(spCPC) spCPC->Release();
/*
	{9bfbbc02-eff1-101a-84ed-00aa00341d07}	IPropertyNotifySink
	{3050f3c4-98b5-11cf-bb82-00aa00bdce0b}	HTMLObjectElementEvents
	{3050f620-98b5-11cf-bb82-00aa00bdce0b}	HTMLObjectElementEvents2
	{00020400-0000-0000-c000-000000000046}	IDispatch
	{1dc9ca50-06ef-11d2-8415-006008c3fbfc}	ITridentEventSink
	{d27cdb6d-ae6d-11cf-96b8-444553540000}	ShockwaveFlashObjects::_IShockwaveFlashEvents
*/
}
void CIncrementSystemBFDlg::ConnectButton1(IHTMLElement *pButtonElem)
{
	HRESULT hr = 0; 
	IConnectionPointContainer* pCPC = NULL; 
	IConnectionPoint* pCP = NULL; 
	IUnknown* pUnk = NULL; 
	DWORD dwCookie; 
	// Check that this is a connectable object. 
	hr = pButtonElem->QueryInterface(IID_IConnectionPointContainer, (void**)&pCPC); 
	if (hr == S_OK) 
	{ 
		//AfxMessageBox("ConnectionPointContainer"); 
		// Find the connection point. 
		IEnumConnectionPoints *ppEnum=NULL;
		hr=pCPC->EnumConnectionPoints(&ppEnum);

	//	ppEnum->Next()
	//	if( hr == S_OK)
		{
			//ppEnum->Next()
		}
		hr = pCPC->FindConnectionPoint(DIID_HTMLinputTextElementEvents2/*DIID_HTMLButtonElementEvents2*/, &pCP); 
	//	hr = pCPC->FindConnectionPoint(__uuidof(IID_HTMLElementEvents2)/*DIID_HTMLButtonElementEvents2*/, &pCP); 
		if   ( SUCCEEDED(hr)) 
		{                         
			//AfxMessageBox( "Find   connection   point   "); 
			//   Advise   the   connection   point. 
			//   pUnk   is   the   IUnknown   interface   pointer   for   your   event   sink 
			
			//CDHTMLEventSink*   pSink   =   new CDHTMLEventSink;// CMyEventSink;// ;   
			//pSink->SetParent(this); 
			//IUnknown*   pUnk   = pSink->GetInterface(&IID_IUnknown);
			
			CMyEventSink* pSink = new CMyEventSink;
			hr   =   pCP->Advise(pSink,   &dwCookie); 
			pCP->Release(); 
		} 
		pCPC->Release(); 
	} 

	
}
// This is called by us to get a connection to IE and start handling IE events
void CObjectWithSite::ConnectEventSink()
{
    HRESULT hr;
    IConnectionPointContainer* pCPC;

    if(pSite==NULL) return; // If we don't have a site, don't do anything
    // Get an IConnectionPointContainer interface pointer from the site
    hr=pSite->QueryInterface(IID_IConnectionPointContainer,(void**)&pCPC);
    if(FAILED(hr)) return; // If we couldn't get it, abort
    // Now we use the IConnectionPointContainer interface to get an IConnectionPoint interface pointer that will handle DWebBrowserEvents2 "dispatch interface" events.
    // That means we have to plug our implementation of DWebBrowserEvents2 into the returned IConnectionPoint interface using its Advise() method, as below
    hr=pCPC->FindConnectionPoint(DIID_DWebBrowserEvents2,&pCP);
    if(FAILED(hr)) { // If it failed, release the pCPC interface pointer and abort
        pCPC->Release();
        return;
    }
    // Finally we can plug our event handler object EventSink into the connection point and start receiving IE events
    // The advise cookie is just a return value we use when we want to "unplug" our event handler object from the connection point
    pCP->Advise((IUnknown*)&EventSink,&adviseCookie);
}
/******************************************************************************
*  AttachToSource -- This method attaches to an event source.
******************************************************************************/ 
STDMETHODIMP CPartProgramSink::AttachToSource( IUnknown* pEventSource )
{
	HRESULT hr = S_OK;

	IConnectionPointContainer* pCPC = NULL;
	hr = pEventSource->QueryInterface( IID_IConnectionPointContainer, 
		(void**)&pCPC );
	if (SUCCEEDED(hr)){

		hr = pCPC->FindConnectionPoint( __uuidof(PCDLRN::IApplicationEvents), 
			&m_pConnectionPoint );
		if (SUCCEEDED(hr)){

			hr = m_pConnectionPoint->Advise( this, &m_dwConnection );
		}
		pCPC->Release();
	}

	return hr;
}