Enable Presence Functionality
Other versions of this page are also available for the following:
8/28/2008
The following code examples demonstrate how to enable presence in RTC. The operations in theInitialize RTC and Register to Receive Events code examples must be performed before using these examples.
Note
This code has not been thoroughly tested, does not contain error checking, and is not intended for production use.
IRTCClientPresence *m_pPresence = NULL;
IRTCBuddy *m_pBuddy = NULL;
BSTR bstrBuddyURI = SysAllocString(_T("somebody@example.com"));
BSTR bstrBuddyName = SysAllocString(_T("My Buddy"));
BSTR bstrBuddyData = SysAllocString(_T("Any Data here"));
VARIANT varPresence;
VariantInit(&varPresence);
varPresence.vt = VT_BSTR;
varPresence.bstrVal = SysAllocString(PRESENCE_STORAGE);
// Get the Presence interface.
hr = m_pIRTCClient->QueryInterface( IID_IRTCClientPresence,
reinterpret_cast<void**> (&m_pPresence));
// If (hr != S_OK), process the error here.
// Automatically add a watcher to the list of allowed watchers.
// There is no need to fire an event.
hr = m_pPresence->put_OfferWatcherMode(
RTCOWM_AUTOMATICALLY_ADD_WATCHER );
// If (hr != S_OK), process the error here.
// Presence has been enabled; now register with the profile.
hr = pIRTCClientProvisioning->EnableProfile( pIRTCProfile,
RTCRF_REGISTER_ALL);
// If (hr != S_OK), process the error here.
// Enable presence using a file for persistent storage.
// If presence functionality is required, it must be
// enabled immediately after registration.
hr = m_pPresence->EnablePresence(VARIANT_TRUE, varPresence );
// If (hr != S_OK), process the error here.
// Track presence information of a presentity.
hr = m_pPresence->AddBuddy( bstrBuddyURI,
bstrBuddyName,
bstrBuddyData,
VARIANT_TRUE,
NULL,
0,
&m_pBuddy );
// If (hr != S_OK), process the error here.