Register to Receive Events

The following code examples show how to register to receive events and listen for incoming calls. The operations in the Initialize the Communications Service example must be performed before using these codes.

**Note   **This code has not been thoroughly tested, does not contain error checking, and is not intended for production use.

//
// Code 1: Set the event filter.
//
HRESULT hr = S_OK;
long lEventMask;
// Set the event mask to receive all event types.
lEventMask = RTCEF_ALL;
hr = pIRTCClient->put_EventFilter(lEventMask);
// if (hr != S_OK) process error here. 
//
// Code 2: Register the event interface. 
//
// Note: This method is in the CRTCOutgoing class, which
// implements the IRTCEventNotification interface.
HRESULT 
CRTCOutgoingDlg::StateSinkEvent(LONG lEventMask)
{
    HRESULT hr = S_OK;
    DWORD dwEventCookie;
    IUnknown *pUnknown = NULL;
    IConnectionPointContainer *pCPC = NULL;
    IConnectionPoint *pCP = NULL;
    hr = QueryInterface( IID_IUnknown,  
                         reinterpret_cast<void**> (&pUnknown) );
    // if (hr != S_OK) process error here.
    // Get the connection point container interface pointer. 
    hr = pIRTCClient->QueryInterface( IID_IConnectionPointContainer, 
                                   reinterpret_cast<void**> (&pCPC) );
    // if (hr != S_OK) process error here.
    // Get the RTC event notification interface 
    // from the connection point container. 
    hr = pCPC->FindConnectionPoint( IID_IRTCEventNotification, &pCP );
    // if (hr != S_OK) process error here.
    // Call the Advise method to give RTC the IUnknown pointer 
    // for the event.
    hr = pCP->Advise( pUnknown, &dwEventCookie ); 
    // if (hr != S_OK) process error here. 
    pCP->Release();
    pCPC->Release();
    pUnknown->Release();
    return hr;
}
//
// Code 3: Listen for calls.
//
// Listen on dynamic and well-known static ports. 
hr = pIRTCClient->put_ListenForIncomingSessions( RTCLM_BOTH ); 
// if (hr != S_OK) process error here.

 Last updated on Saturday, April 10, 2004

© 1992-2003 Microsoft Corporation. All rights reserved.