Share via


Initialize RTC

The following code example demonstrates the creation and initialization of the RTC object.

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

C++ Code Example

HRESULT hr = S_OK;

// RTC Initialization 
// Note: Use the apartment threaded model because
// RTC applications are not thread safe.
::CoInitializeEx(NULL,COINIT_APARTMENTTHREADED);

// Create the RTC Client COM object. 
IRTCClient      *pIRTCClient;

hr = CoCreateInstance( CLSID_RTCClient,
                       NULL,
                       CLSCTX_INPROC_SERVER,
                       IID_IRTCClient,
                       reinterpret_cast<void **> (&pIRTCClient) );

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

// Initialize the RTCClient interface. 
hr = pIRTCClient->Initialize();

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

Visual Basic Code Example

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

'Declare the global RTC Client object.
Private g_objRTCClient As RTCClient

'Create the RTC Client object, usually performed during form load.
Set g_objRTCClient = New RTCClient

'RTCClient needs to be initialized before any other method can be 
called on it.
Call g_objRTCClient.Initialize