Share via


Shut Down RTC

The following code example demonstrates how to shut down the RTC client. The operations in the Initialize RTC code example must be performed before using this example.

Note  This example does not contain error checking or releases appropriate for real code.

C++ Code Example

HRESULT hr  = S_OK;

// Asynchronously prepare the client object for 
// shutting down. No new sessions can be initiated 
// after calling this method. For UI-based applications,
// it is recommended that applications call
// IRTCClient::PrepareForShutdown first and then  
// hide the UI window until the RTCCET_ASYNC_CLEANUP_DONE
// event is fired and the UI window is destroyed.

hr = pIRTCClient->PrepareForShutdown();

// If (hr != S_OK), process the error here.

// The call to PrepareForShutdown will fire 
// an RTC_CLIENT event of type RTCCET_ASYNC_CLEANUP_DONE.
// In the RTC_CLIENT IRTCClientEvent handler method, call shutdown
// on the client and release the client object after receiving this 
// event.

....

// In the RTC_CLIENT event handler

IRTCClientEvent         *pIClientEvent = NULL;
RTC_CLIENT_EVENT_TYPE   EventType;

// Get the client event interface.
hr = pIDispatch->QueryInterface(IID_IRTCClientEvent,
                           reinterpret_cast<void**> (&pIClientEvent));

// If (hr != S_OK), process the error here.

hr = pIClientEvent->get_EventType(&EventType);

// If (hr != S_OK), process the error here.

switch(EventType) 
{
    // Handle the case for completion of the 
    // PrepareForShutdown method.
    case RTCCET_ASYNC_CLEANUP_DONE :
    {
        // This method cleans up the client object and 
        // must be called before releasing the object.
        hr = pIRTCClient->Shutdown();
 
        // If (hr != S_OK), process the error here.

        pIRTCClient->Release();
        pIRTCClient = NULL;
        break;
    }
    .....
}

Visual Basic Code Example

' To shut down the RTC Client, first call PrepareForShutdown then wait 
' for the RTCE_CLIENT event RTCCET_ASYNC_CLEANUP_DONE. This event 
' is fired upon completion of PrepareForShutdown and in the 
' events handler call IRTCClient.Shutdown after the clean up is
' received.

' For UI-based applications, it is recommended on application shutdown 
' to call IRTCClient.PrepareForShutdown and hide the UI window until the 
' RTCCET_ASYNC_CLEANUP_DONE event is fired before destroying
' the UI window.

' In the method for handling user events (for example, the user clicks
' an Exit button).
' Asynchronously prepare the client object for shutting down. No new 
' sessions can be initiated after calling this method.

' Set the error handling routine here. 
' On Error GoTo MyErrorRoutine 

Call g_objRTCClient.PrepareForShutdown

' In the RTC_CLIENT event handler
Dim EventType As RTC_CLIENT_EVENT_TYPE
Dim objClientEvent As IRTCClientEvent
   
' pEvent is an "Unknown" object; query it
' to get the IRTCSessionStateChangeEvent interface.
Set objClientEvent = pEvent
EventType = objClientEvent.EventType
    
Select Case EventType

    Case RTCCET_ASYNC_CLEANUP_DONE
        ' Shutdown must be called before the client object is 
        ' released.
        Call g_objRTCClient.Shutdown
        Set g_objRTCClient = Nothing
        ....

End Select