예제 #1
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
예제 #2
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;
	}	
}
// 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);
}
예제 #4
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();
}
예제 #5
0
파일: cmdwatch.cpp 프로젝트: Ashatta/tools
int main(int argc, char * argv[])
{
	IKernelLog *		pKernelLog;
	IKernelLogEvents *	psKernelLogEvents;
	IConnectionPoint *	cp;
	DWORD				cookie;
	MSG msg;

	IKernelLogEvents a;

	::CoInitialize(NULL);

	destination = 0;
	tmain_threadid = ::GetCurrentThreadId();

	if(!FAILED(::CoCreateInstance(CLSID_KernelLog, NULL, CLSCTX_ALL, __uuidof(IKernelLog), (void **)&pKernelLog)))
	{
		cp = NULL;
		psKernelLogEvents = new IKernelLogEvents;

		if(Advise(pKernelLog, __uuidof(_IKernelLogEvents), psKernelLogEvents, &cookie, &cp))
		{
			::SetConsoleCtrlHandler(HandlerRoutine, TRUE);
			while(::GetMessage(&msg, NULL, 0, 0) != 0)
			{   ::DispatchMessage(&msg);   }
			::SetConsoleCtrlHandler(HandlerRoutine, FALSE);
			
			cp->Unadvise(cookie);
		}

		delete psKernelLogEvents;

		if(pKernelLog != NULL)
			pKernelLog->Release();
	}

	if(destination != NULL)
	{
		Printf("\n\nSuspended by Ctrl-C event occursion.\n");
		fclose(destination);
	}

	::CoUninitialize();
	return 0;
}
// @pymethod |PyIConnectionPoint|Unadvise|Terminates an advisory connection previously established through IConnectionPoint::Advise. The dwCookie parameter identifies the connection to terminate.
PyObject *PyIConnectionPoint::Unadvise(PyObject *self, PyObject *args)
{
	DWORD cookie;
	// @pyparm int|cookie||The connection token
	if ( !PyArg_ParseTuple(args, "i:Unadvise", &cookie) )
		return NULL;

	IConnectionPoint *pICP = GetI(self);
	if ( pICP == NULL )
		return NULL;

	PY_INTERFACE_PRECALL;
	HRESULT hr = pICP->Unadvise(cookie);
	PY_INTERFACE_POSTCALL;
	if ( FAILED(hr) )
		return SetPythonCOMError(self,hr);

	Py_INCREF(Py_None);
	return Py_None;
}
void Win32WebControl::removeWebView()
{
    if (_connectionPoint != NULL)
    {
        _connectionPoint->Unadvise(_cookie);
        _connectionPoint->Release();
        _connectionPoint = NULL;
    }
    if (_htmlDoc != NULL)
    {
        _htmlDoc->Release();
        _htmlDoc = NULL;
    }
    if (_webBrowser2 != NULL)
    {
        _webBrowser2->Release();
        _webBrowser2 = NULL;
    }
    _winContainer.DestroyWindow();
}
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"));
    }
}
예제 #9
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;
}
예제 #10
0
STDMETHODIMP COPCGroupImpl::put_IsSubscribed(VARIANT_BOOL IsSubscribed)
{
   if( !m_pOPCGroup )
      return E_FAIL;

   HRESULT hr=S_OK;
   if( IsSubscribed == m_subscribed )
      return hr;

   if( IsSubscribed )
   {
      if( m_usingCP )
      {
         IConnectionPointContainer *pCPC = 0;
         hr = m_pOPCGroup->QueryInterface(IID_IConnectionPointContainer, (LPVOID*)&pCPC);
         if( SUCCEEDED(hr) )
         {
            IConnectionPoint *pCallbackCP = 0;
            hr = pCPC->FindConnectionPoint(IID_IOPCDataCallback, &pCallbackCP);
            pCPC->Release();
            if( FAILED(hr) )
            {
               return E_FAIL;
            }

            IUnknown* pUnk = NULL;
            ((COPCGroup*)this)->QueryInterface( IID_IUnknown, (LPVOID*)&pUnk);
            hr = pCallbackCP->Advise(pUnk, &m_DataConnection);
            pCallbackCP->Release();
            pUnk->Release();
            if( FAILED(hr) )
            {
               return E_FAIL;
            }
         }
      }
      else
      {
         if( !m_pIDataObject )
         {
            m_pIDataObject = m_pOPCGroup;   // get IDataObject Interface
            if( !m_pIDataObject )
               return E_FAIL;
         }

         IAdviseSink *pAdviseSink = NULL;

         hr = ((COPCGroup*)this)->QueryInterface(IID_IAdviseSink, (LPVOID *)&pAdviseSink);
         if (FAILED(hr))
         {
            return E_FAIL;
         }

         FORMATETC formatEtc ;
         formatEtc.cfFormat = OPCSTMFORMATDATATIME;
         formatEtc.tymed =  TYMED_HGLOBAL;
         formatEtc.ptd = NULL;
         formatEtc.dwAspect = DVASPECT_CONTENT;
         formatEtc.lindex = -1;

         hr = m_pIDataObject->DAdvise(&formatEtc,
                                    (DWORD)ADVF_PRIMEFIRST,
                                    pAdviseSink,
                                    &m_DataConnection);

         if( SUCCEEDED(hr) )  // also advise write complete
         {
            formatEtc.cfFormat = OPCSTMFORMATWRITECOMPLETE;
            hr = m_pIDataObject->DAdvise(&formatEtc,
                                       (DWORD)ADVF_PRIMEFIRST,
                                       pAdviseSink,
                                       &m_WriteConnection);
         }
         // DAdvise will hold its own reference
         pAdviseSink->Release();
      }
      m_subscribed = VARIANT_TRUE;
   }
   else  // Unsubscribing
   {
      if( m_usingCP )
      {
         // OPC 2.0 ConnectionPoints
         IConnectionPointContainer *pCPC = 0;
         hr = m_pOPCGroup->QueryInterface(IID_IConnectionPointContainer, (LPVOID*)&pCPC);
         if( SUCCEEDED(hr) )
         {
            IConnectionPoint *pCallbackCP = 0;
            hr = pCPC->FindConnectionPoint(IID_IOPCDataCallback, &pCallbackCP);
            if( SUCCEEDED(hr) )
            {
               hr = pCallbackCP->Unadvise(m_DataConnection);
               pCallbackCP->Release();
            }
            pCPC->Release();
         }
      }
      else
      {
         if( m_pIDataObject.p )   // if a valid interface pointer
         {
            hr = m_pIDataObject->DUnadvise(m_DataConnection);
            if( SUCCEEDED(hr) )  // also unadvise write complete
               hr = m_pIDataObject->DUnadvise(m_WriteConnection);
            m_pIDataObject.Release();
         }
      }
      m_subscribed = VARIANT_FALSE;
   }

   return hr;
}
예제 #11
0
//*******************************************************************
void COpcC_Client::DoOpcDisconnect()
{
   CWaitCursor wait;
   HRESULT hr = S_OK;
   if( opcServer.IsOk() && opcGroup.IsOk() )
   {
      if( dwShutdownConnection )
      {
         IConnectionPointContainer *pCPC = 0;
         hr = opcServer.QueryInterface(IID_IConnectionPointContainer, (void**)&pCPC);
         if( SUCCEEDED(hr) )
         {
            IConnectionPoint *pCallbackCP = 0;
            hr = pCPC->FindConnectionPoint(IID_IOPCShutdown, &pCallbackCP);
            if( SUCCEEDED(hr) )
            {
               hr = pCallbackCP->Unadvise(dwShutdownConnection);
               pCallbackCP->Release();
            }
            pCPC->Release();
         }
      }
      if( usingCP )
      {
         // OPC 2.0 ConnectionPoints
         IConnectionPointContainer *pCPC = 0;
         hr = opcGroup.QueryInterface(IID_IConnectionPointContainer, (void**)&pCPC);
         if( SUCCEEDED(hr) && dwConnection1 )  // This server supports 2.0
         {
            IConnectionPoint *pCallbackCP = 0;
            hr = pCPC->FindConnectionPoint(IID_IOPCDataCallback, &pCallbackCP);
            if( SUCCEEDED(hr) )
            {
               hr = pCallbackCP->Unadvise(dwConnection1);
               pCallbackCP->Release();
            }
            pCPC->Release();
         }
      }
      else
      // call IDataObject::DUnadvise to turn off data notification
      {
          DataObject dataObject;
          HRESULT hr = dataObject.Attach( opcGroup );
          if( SUCCEEDED(hr) )
          {
             if( dwConnection1 )
                hr = dataObject.DUnadvise(dwConnection1);
             if( dwConnection2 )
                hr = dataObject.DUnadvise(dwConnection2);
             dataObject.Detach();
          }
       }

       opcServer.RemoveGroup(groupHandle, FALSE);

   }
   opcGroup.Detach();
   opcServer.Detach();

   Sleep( 100 );

   // now that the group is released and unadvised, no more data will
   // be sent from the server. It is safe to delete the items
   while( !items.IsEmpty() )
      delete items.RemoveTail();
}
예제 #12
0
// **************************************************************************
// Disconnect ()
//
// Description:
//	Called to disconnect from OPC server.
//
// Parameters:
//  none
//
// Returns:
//  void
// **************************************************************************
void CKServer::Disconnect ()
	{
	// Log success if we were truly connected:
	if (m_bConnected == true)
		LogMsg (IDS_SERVER_DISCONNECTED, GetProgID ());

	// Reset member variable:
	m_bConnected = false;

	// Release all of our server interface references:
	if (m_pIServer)
		{
		m_pIServer->Release ();
		m_pIServer = NULL;
		}

	if (m_pICommon)
		{
		m_pICommon->Release ();
		m_pICommon = NULL;
		}

	if (m_pIConnPtContainer)
		{
		// Unadvise shutdown notifications:
		if (m_dwCookieShutdownSink != 0)
			{
			HRESULT hr = E_FAIL;
			IConnectionPoint *pCP = NULL;

			hr = m_pIConnPtContainer->FindConnectionPoint (IID_IOPCShutdown, &pCP);

			if (SUCCEEDED (hr))
				{
				hr = pCP->Unadvise (m_dwCookieShutdownSink);
				pCP->Release ();
				}

			if (FAILED (hr))
				{
				TRACE (_T("OTC: CKServer::Disconnect () - failed to unadvise shutdown notifications\r\n"));
				}

			m_dwCookieShutdownSink = 0;
			}

		if (m_pIShutdownSink != NULL)
			{
			m_pIShutdownSink->Release ();
			m_pIShutdownSink = NULL;
			}

		m_pIConnPtContainer->Release ();
		m_pIConnPtContainer = NULL;
		}

	if (m_pIItemProps)
		{
		m_pIItemProps->Release ();
		m_pIItemProps = NULL;
		}

	if (m_pIBrowse)
		{
		m_pIBrowse->Release ();
		m_pIBrowse = NULL;
		}

	if (m_pIPublicGroups)
		{
		m_pIPublicGroups->Release ();
		m_pIPublicGroups = NULL;
		}

	if (m_pIPersistFile)
		{
		m_pIPersistFile->Release ();
		m_pIPersistFile = NULL;
		}
	}