Exemplo n.º 1
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 NULL;
  }

  {
    IID guid;

    server->GetIID(&guid);

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

  pcpc->Release();
  pcpc = NULL;

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

  DWORD connection_point_cookie;

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

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

    return NULL;
  }

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

  return connection_point_cookie;
}
Exemplo n.º 2
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;
}
Exemplo n.º 3
0
void CAddUserRequest::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);
	}
}
Exemplo n.º 4
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();
    }
}
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;
}
Exemplo n.º 6
0
Arquivo: ZDrOle.cpp Projeto: DeegC/10d
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
Exemplo n.º 7
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 */
Exemplo n.º 8
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;
	}	
}
Exemplo n.º 9
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);
	}
}
Exemplo n.º 10
0
// 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);
}
Exemplo n.º 11
0
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;
}
Exemplo n.º 12
0
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;
}
Exemplo n.º 14
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
Exemplo n.º 15
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();
}
Exemplo n.º 16
0
/*
** 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();
}
Exemplo n.º 17
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;
}
// 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;
}
Exemplo n.º 19
0
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;
}
Exemplo n.º 20
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;
}
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;
}
Exemplo n.º 24
0
void CXTPReportDataManager::RemoveDataSource()
{
    try
    {
        // unadvise events
        if (m_pRstEvent)
        {
            IConnectionPointContainer *pCPC = NULL;
            IConnectionPoint *pCP = NULL;
            HRESULT hr = m_pDataSource->QueryInterface(__uuidof(IConnectionPointContainer), (void**)&pCPC);
            if (SUCCEEDED(hr))
            {
                hr = pCPC->FindConnectionPoint(__uuidof(XTPREPORTADODB::RecordsetEvents), &pCP);
                pCPC->Release();
                if (SUCCEEDED(hr))
                {
                    hr = pCP->Unadvise(m_dwRstEvent);
                    pCP->Release();
                }
            }
            //delete m_pRstEvent;
            m_pRstEvent->Release();
            m_pRstEvent = NULL;
        }
        // set data source pointer to NULL
        m_pDataSource = NULL;

    }
    catch(_com_error &e)
    {
        TRACE_ProviderError(m_pConnection);
        TRACE_ComError(e);
    }
    catch(...)
    {
        TRACE(_T("Unknown error in RemoveDataSource()\n"));
    }
}
Exemplo n.º 25
0
    void createBrowser()
    {
        createControl (&CLSID_WebBrowser);
        browser = (IWebBrowser2*) queryInterface (&IID_IWebBrowser2);

        IConnectionPointContainer* connectionPointContainer = (IConnectionPointContainer*) queryInterface (&IID_IConnectionPointContainer);

        if (connectionPointContainer != nullptr)
        {
            connectionPointContainer->FindConnectionPoint (DIID_DWebBrowserEvents2,
                                                           &connectionPoint);

            if (connectionPoint != nullptr)
            {
                WebBrowserComponent* const owner = dynamic_cast <WebBrowserComponent*> (getParentComponent());
                jassert (owner != nullptr);

                EventHandler* handler = new EventHandler (*owner);
                connectionPoint->Advise (handler, &adviseCookie);
                handler->Release();
            }
        }
    }
Exemplo n.º 26
0
void tLuaCOM::releaseConnection(tLuaCOM* server, DWORD cookie)
{
  IConnectionPointContainer *pcpc = NULL;

  IConnectionPoint *connection_point;

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

  if(FAILED(hr))
  {
	  LUACOM_ERROR("Object does not accept connections!");
  }

  {
    IID guid;

    server->GetIID(&guid);

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

  pcpc->Release();
  pcpc = NULL;

  if(FAILED(hr))
  {
    LUACOM_ERROR("No connection point for this interface!");
  }

  connection_point->Unadvise(cookie);
  connection_point->Release();
  connection_point = NULL;
}
Exemplo n.º 27
0
void CInviteChatDlg::CloseMpaWebEvent()
{
	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))
		{
			hr = m_pSessionConnectionPoint->Unadvise(m_dwSessionCookie);
			pCPContainer->Release();
		}
		else
		{
			ASSERT(FALSE);
		}
	}
	else
	{
		ASSERT(FALSE);
	}
}
Exemplo n.º 28
0
HRESULT UnRegisterCallBack()
{
    LogMessage("UnRegisterCallBack: started");

    HRESULT hr = S_OK;


    //
    // get connection point container on the tapi object
    // 
    
    IConnectionPointContainer *pCPContainer = NULL;

    hr = g_pTapi->QueryInterface(IID_IConnectionPointContainer,
                                (void **)&pCPContainer);

    if (FAILED(hr))
    {
        LogError("UnRegisterCallBack: "
                 "Failed to get IConnectionPointContainer on TAPI");

        return hr;
    }


    //
    // find connection point for our interface
    //

    IConnectionPoint *pConnectionPoint = NULL;

    hr = pCPContainer->FindConnectionPoint(IID_ITTAPIEventNotification,
                                           &pConnectionPoint);

    pCPContainer->Release();
    pCPContainer = NULL;

    if (FAILED(hr))
    {
        LogError("RegisterCallback: Failed to get a connection point for "
                 "ITTAPIEventNotification");

        return hr;
    }


    // 
    // unregister the callback
    //
    
    hr = pConnectionPoint->Unadvise(g_nTAPINotificationCookie);

    pConnectionPoint->Release();
    pConnectionPoint = NULL;

    g_nTAPINotificationCookie = 0;

    if (FAILED(hr))
    {
        LogError("UnRegisterCallBack: Unadvise failed");
    }
    else
    {
        LogMessage("UnRegisterCallBack: succeeded");
    }


    return hr;
}
// Initialize this print job checker by registering a print document package target.
// This is required before the application can use this print job checker to monitor a print job.
HRESULT D2DPrintJobChecker::Initialize(
    _In_ IPrintDocumentPackageTarget* documentPackageTarget
    )
{
    // Application can only initialize this job checker once.
    if (m_isInitialized)
    {
        return E_FAIL;
    }

    HRESULT hr = (documentPackageTarget != nullptr) ? S_OK : E_INVALIDARG;

    IConnectionPointContainer* connectionPointContainer = nullptr;
    if (SUCCEEDED(hr))
    {
        hr = documentPackageTarget->QueryInterface(IID_PPV_ARGS(&connectionPointContainer));
    }

    if (SUCCEEDED(hr))
    {
        hr = connectionPointContainer->FindConnectionPoint(
            __uuidof(IPrintDocumentPackageStatusEvent),
            &m_connectionPoint
            );
    }

    IUnknown* unknownEvent = nullptr;
    if (SUCCEEDED(hr))
    {
        hr = this->QueryInterface(IID_PPV_ARGS(&unknownEvent));
    }

    if (SUCCEEDED(hr))
    {
        hr = m_connectionPoint->Advise(unknownEvent, &m_eventCookie);
    }

    // Create an event handle for print job completion.
    if (SUCCEEDED(hr))
    {
        m_completionEvent = ::CreateEvent(
            nullptr, // The handle cannot be inherited by child processes.
            TRUE,    // The event object requires the use of the ResetEvent function to set the event state to nonsignaled.
            FALSE,   // The initial state of the event object is nonsignaled.
            nullptr  // Name of the event object.
            );
        hr = (!m_completionEvent) ? HRESULT_FROM_WIN32(::GetLastError()) : hr;
    }

    if (unknownEvent)
    {
        unknownEvent->Release();
        unknownEvent = nullptr;
    }
    if (connectionPointContainer)
    {
        connectionPointContainer->Release();
        connectionPointContainer = nullptr;
    }

    if (SUCCEEDED(hr))
    {
        m_isInitialized = true;
    }
    else
    {
        ReleaseResources();
    }

    return hr;
}
Exemplo n.º 30
0
IEView::IEView(HWND parent, HTMLBuilder* builder, int x, int y, int cx, int cy) {
	MSG msg;
	IOleObject*   pOleObject = NULL;
    IOleInPlaceObject *pOleInPlace;
	this->parent = parent;
	this->builder = builder;
	this->smileyWindow = NULL;
	prev = next = NULL;
	hwnd = NULL;
	sink = NULL;
	pWebBrowser = NULL;
	m_pConnectionPoint = NULL;
	m_cRef = 0;
#ifdef GECKO
	if (SUCCEEDED(CoCreateInstance(CLSID_MozillaBrowser, NULL, CLSCTX_INPROC, IID_IWebBrowser2, (LPVOID*)&pWebBrowser))) {
#else
	if (SUCCEEDED(CoCreateInstance(CLSID_WebBrowser, NULL, CLSCTX_INPROC, IID_IWebBrowser2, (LPVOID*)&pWebBrowser))) {
#endif
//		pWebBrowser->put_RegisterAsBrowser(VARIANT_FALSE);
//		pWebBrowser->put_RegisterAsDropTarget(VARIANT_FALSE);
		if (SUCCEEDED(pWebBrowser->QueryInterface(IID_IOleObject, (void**)&pOleObject))) {
    		rcClient.left = x;
    		rcClient.top = y;
    		rcClient.right = x + cx;
    		rcClient.bottom = y + cy;
    		pOleObject->SetClientSite(this);
    		pOleObject->DoVerb(OLEIVERB_INPLACEACTIVATE, &msg, this, 0, parent, &rcClient);
    		pOleObject->Release();
   		} else {
  			MessageBox(NULL,"IID_IOleObject failed.","RESULT",MB_OK);
   		}

		if (SUCCEEDED(pWebBrowser->QueryInterface(IID_IOleInPlaceObject, (void**)&pOleInPlace))) {
    		pOleInPlace->GetWindow(&hwnd);
    		pOleInPlace->Release();
		} else {
  			MessageBox(NULL,"IID_IOleInPlaceObject failed.","RESULT",MB_OK);
		}

		LONG style = GetWindowLong(hwnd, GWL_EXSTYLE);
		style |= (WS_EX_STATICEDGE);
		SetWindowLong(hwnd,GWL_EXSTYLE,style);

   		IConnectionPointContainer* pCPContainer;
	   // Step 1: Get a pointer to the connection point container.
   		if (SUCCEEDED(pWebBrowser->QueryInterface(IID_IConnectionPointContainer,
                                      		(void**)&pCPContainer))) {
	      // m_pConnectionPoint is defined like this:
	      // Step 2: Find the connection point.
      		if (SUCCEEDED(pCPContainer->FindConnectionPoint(DIID_DWebBrowserEvents2,
	                                             &m_pConnectionPoint))) {
	         // Step 3: Advise the connection point that you
	         // want to sink its events.
	            sink = new IEViewSink();
#ifndef GECKO
	         	if (FAILED(m_pConnectionPoint->Advise((IUnknown *)sink, &m_dwCookie)))     {
	            	MessageBox(NULL, "Failed to Advise", "C++ Event Sink", MB_OK);
	         	}
#endif
	      	}
      		pCPContainer->Release();
   		}
#ifndef GECKO
		setUserWndProc((WNDPROC)SetWindowLong(hwnd, GWL_WNDPROC, (LONG) IEViewWindowProcedure));
#endif
    }
    EnterCriticalSection(&mutex);
	next = list;
	if (next != NULL) {
	    next->prev = this;
	}
	list = this;
	LeaveCriticalSection(&mutex);
	clear();
}

IEView::IEView(HWND parent, SmileyWindow* smileyWindow, int x, int y, int cx, int cy) {
	MSG msg;
	IOleObject*   pOleObject = NULL;
    IOleInPlaceObject *pOleInPlace;
	this->parent = parent;
	builder = NULL;
	this->smileyWindow = smileyWindow;
	prev = next = NULL;
	hwnd = NULL;
	sink = NULL;
	pWebBrowser = NULL;
	m_pConnectionPoint = NULL;
	m_cRef = 0;

#ifdef GECKO
	if (SUCCEEDED(CoCreateInstance(CLSID_MozillaBrowser, NULL, CLSCTX_INPROC, IID_IWebBrowser2, (LPVOID*)&pWebBrowser))) {
#else
	if (SUCCEEDED(CoCreateInstance(CLSID_WebBrowser, NULL, CLSCTX_INPROC, IID_IWebBrowser2, (LPVOID*)&pWebBrowser))) {
#endif
//		pWebBrowser->put_RegisterAsBrowser(VARIANT_FALSE);
//		pWebBrowser->put_RegisterAsDropTarget(VARIANT_FALSE);
		if (SUCCEEDED(pWebBrowser->QueryInterface(IID_IOleObject, (void**)&pOleObject))) {
    		rcClient.left = x;
    		rcClient.top = y;
    		rcClient.right = x + cx;
    		rcClient.bottom = y + cy;
    		pOleObject->SetClientSite(this);
    		pOleObject->DoVerb(OLEIVERB_INPLACEACTIVATE, &msg, this, 0, parent, &rcClient);
    		pOleObject->Release();
   		} else {
  			MessageBox(NULL,"IID_IOleObject failed.","RESULT",MB_OK);
   		}

		if (SUCCEEDED(pWebBrowser->QueryInterface(IID_IOleInPlaceObject, (void**)&pOleInPlace))) {
    		pOleInPlace->GetWindow(&hwnd);
    		pOleInPlace->Release();
		} else {
  			MessageBox(NULL,"IID_IOleInPlaceObject failed.","RESULT",MB_OK);
		}

   		IConnectionPointContainer* pCPContainer;
	   // Step 1: Get a pointer to the connection point container.
   		if (SUCCEEDED(pWebBrowser->QueryInterface(IID_IConnectionPointContainer,
                                      		(void**)&pCPContainer))) {
	      // m_pConnectionPoint is defined like this:
	      // Step 2: Find the connection point.
      		if (SUCCEEDED(pCPContainer->FindConnectionPoint(DIID_DWebBrowserEvents2,
	                                             &m_pConnectionPoint))) {
	         // Step 3: Advise the connection point that you
	         // want to sink its events.
	            sink = new IEViewSink(smileyWindow);
#ifndef GECKO
	         	if (FAILED(m_pConnectionPoint->Advise((IUnknown *)sink, &m_dwCookie)))     {
	            	MessageBox(NULL, "Failed to Advise", "C++ Event Sink", MB_OK);
	         	}
#endif
	      	}
      		pCPContainer->Release();
   		}
    }
	clear();
}

IEView::~IEView() {
	IOleObject*   pOleObject = NULL;
	if (SUCCEEDED(pWebBrowser->QueryInterface(IID_IOleObject, (void**)&pOleObject))) {
		pOleObject->SetClientSite(NULL);
		pOleObject->Release();
	} else {
		MessageBox(NULL,"IID_IOleObject failed.","RESULT",MB_OK);
	}
    EnterCriticalSection(&mutex);
	if (list == this) {
		list = next;
	} else if (prev!=NULL) {
		prev->next = next;
	}
	if (next != NULL) {
		next->prev = prev;
	}
	LeaveCriticalSection(&mutex);
	if (builder != NULL) {
		delete builder;
		builder = NULL;
	}
	if (m_pConnectionPoint != NULL) {
        m_pConnectionPoint->Unadvise(m_dwCookie);
        m_pConnectionPoint->Release();
	}
	if (sink != NULL) {
		delete sink;
	}
	pWebBrowser->Release();
	DestroyWindow(hwnd);
}

void IEView::setUserWndProc(WNDPROC wndProc) {
	userWndProc = wndProc;
}

WNDPROC IEView::getUserWndProc() {
	return userWndProc;
}

// IUnknown
STDMETHODIMP IEView::QueryInterface(REFIID riid, PVOID *ppv) {
	*ppv=NULL;
	if (IID_IUnknown==riid)
		*ppv=this;
	if (IID_IOleClientSite==riid)
		*ppv=(IOleClientSite*)this;//Unknown)m_pIOleClientSite;
	if (IID_IOleWindow==riid || IID_IOleInPlaceSite==riid)
		*ppv=(IOleInPlaceSite*)this;//m_pIOleIPSite;
	if (IID_IDocHostUIHandler==riid)
		*ppv=(IDocHostUIHandler*)this;//m_pIOleIPSite;
	if (NULL!=*ppv) {
		((LPUNKNOWN)*ppv)->AddRef();
		return NOERROR;
	}
	return E_NOINTERFACE;
}