Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
The following code example demonstrates how to add the various types of buddies with the IRTCClientPresence2::AddBuddyEx method. 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
//
// Set common parameters.
//
// Set the URI of the buddy that will be added.
BSTR bstrPresentityURI = NULL;
// Set the user name or choose NULL
// if you do not want to provide one.
BSTR bstrUserName = NULL;
// Set the data for a buddy; this is optional data.
BSTR bstrData = ::SysAllocString(L"Sample Data, for example, URL for buddy's Web page");
// Make the buddy persisted/roamed.
VARIANT_BOOL fPersistent = VARIANT_TRUE;
IRTCProfile *pProfile = NULL // set this to the profile used to connect to your server
// The lFlags in AddBuddyEx are used only
// if you want to fail on redirect.
long lFlags = 0;
// The buddy interface is returned from the AddBuddyEx method.
IRTCBuddy2 *pBuddy = NULL;
//
// Add a standard subscribed buddy.
//
bstrPresentityURI = ::SysAllocString(L"user1@example.com");
hr = AddBuddyEx(bstrPresentityURI,
bstrUserName,
bstrData,
fPersistent,
RTCBT_SUBSCRIBED,
pProfile,
lFlags,
&pBuddy);
// If (hr != S_OK), process the error here.
// Expect two or three buddy events to be fired.
// The types are buddy_add, buddy_subscribed, and
// buddy_state_change if you receive a notification
// of presence. The status code from the event will
// indicate whether the operation was successful or not.
// Perform cleanup.
if (bstrPresentityURI)
{
::SysFreeString(bstrPresentityURI);
bstrPresentityURI = NULL;
}
if (pBuddy)
{
pBuddy->Release();
pBuddy = NULL;
}
//
// Add an always online buddy.
//
bstrPresentityURI = ::SysAllocString(L"user2@example.com");
hr = AddBuddyEx(bstrPresentityURI,
bstrUserName,
bstrData,
fPersistent,
RTCBT_ALWAYS_ONLINE ,
pProfile,
lFlags,
&pBuddy);
// If (hr != S_OK), process the error here.
// Expect one buddy event to be fired. The type is
// buddy_add. The status code from the event indicates
// whether the operation was successful.
// Perform cleanup.
if (bstrPresentityURI)
{
::SysFreeString(bstrPresentityURI);
bstrPresentityURI = NULL;
}
if (pBuddy)
{
pBuddy->Release();
pBuddy = NULL;
}
//
// Add an always offline buddy.
//
bstrPresentityURI = ::SysAllocString(L"user3@example.com");
hr = AddBuddyEx(bstrPresentityURI,
bstrUserName,
bstrData,
fPersistent,
RTCBT_ALWAYS_OFFLINE,
pProfile,
lFlags,
&pBuddy);
// If (hr != S_OK), process the error here.
// Expect one buddy event to be fired. The type is
// buddy_add. The status code from the event indicates
// whether the operation was successful.
// Perform cleanup.
if (bstrPresentityURI)
{
::SysFreeString(bstrPresentityURI);
bstrPresentityURI = NULL;
}
if (pBuddy)
{
pBuddy->Release();
pBuddy = NULL;
}
Visual Basic Code Example
Dim pProfile As IRTCProfile
Dim pPresence2 As IRTCClientPresence2
' Add Code: Set pProfile to the profile
' used to connect to your server.
' Add Code: Set pPresence2 to the client object.
Dim pBuddy As IRTCBuddy2
'
' Add a standard subscribed buddy.
'
Set pBuddy = pPresence2.AddBuddyEx("Subscribed@example.com", _
vbNullString, _
vbNullString, _
True, _
RTCBT_SUBSCRIBED, _
pProfile, 0)
' Expect two or three buddy events to be fired. The
' types are buddy_add, buddy_subscribed, and
' buddy_state_change if you receive a notification of
' presence. The status code from the event indicates
' whether the operation was successful.
' Perform cleanup.
Set pBuddy = Nothing
'
' Add an always online buddy.
'
Set pBuddy = pPresence2.AddBuddyEx("alwaysonline@example.com", _
vbNullString, _
vbNullString, _
True, _
RTCBT_ALWAYS_ONLINE, _
pProfile, 0)
' Expect one buddy event to be fired. The type is
' buddy_add. The status code from the event indicates
' whether the operation was successful.
' Perform cleanup.
Set pBuddy = Nothing
'
' Add an always offline buddy.
'
Set pBuddy = pPresence2.AddBuddyEx("alwaysoffline@example.com", _
vbNullString, _
vbNullString, _
True, _
RTCBT_ALWAYS_OFFLINE, _
pProfile, 0)
' Expect one buddy event to be fired. The type is
' buddy_add. The status code from the event indicates
' whether the operation was successful or not.
' Perform cleanup.
Set pBuddy = Nothing