Share via


Create the Roaming Profile

The following code example demonstrates how to create the profile used for roaming. The operations in the Initialize RTC code example must be performed before using this example.

The profile created by the IRTCClientProvisioning::GetProfile method is returned asynchronously from the server. The application receives an event of type RTCE_PROFILE to indicate the profile has been returned. The IRTCEventNotification::Event method returns the IRTCProfileEvent interface in the pEvent parameter. The IRTCProfileEvent::get_Profile property contains the profile in the ppProfile parameter. For more information on receiving the profile event, see the Roaming Events code example.

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

C++ Code Example

HRESULT LogonWithRoaming(IRTCClient *pClient, 
                         BSTR bstrUsername, 
                         BSTR bstrPassword, 
                         BSTR bstrURI, 
                         BSTR bstrServername )
{
    HRESULT hr = S_OK;
    IRTCClientProvisioning2 *pProv2 = NULL; 
    long lCookie = 0;
	
    // Query for the IRTCClientProvisioning2 interface.
    hr = pClient->QueryInterface(IID_IRTCClientProvisioning2, 
                                 (LPVOID *)&pProv2);
	
    // If (hr != S_OK), process the error here.

    // Get the profile to use for roaming.
    hr = pProv2->GetProfile(bstrUsername, 
                            bstrPassword, 
                            bstrURI, 
                            bstrServername, 
                            RTCTR_TCP, 
                            lCookie);
	
    // If (hr != S_OK), process the error here.

    // Release the reference to the 
    // IRTCClientProvisioning2 interface. 
    if (pProv2)
    {
        pProv2->Release();
    }  
    Return S_OK
}

Visual Basic Code Example

'
' Start the process by getting a profile.
'
Dim pProv2 As IRTCClientProvisioning2

' Receive the provisioning interface from the 
' main client object.
pProv2 = pClient

Call pProv2.GetProfile("username", _
                       "password", _
                       "uri@microsoft.com", _
                       "servername.microsoft.com", _
                       RTCTR_TCP, 0)

' After receiving the profile in the profile 
' event, continue the process within the
' event handler.

Dim pPE2 As IRTCProfileEvent2

' Add code here to set pPE2 to the Event object.
pPE2 = pEvent

Dim pProfile2 As IRTCProfile2
Dim enType As long

Set pProfile = pPE2.Profile

Set enType = pPE2.EventType

If (enType = RTCPFET_PROFILE_GET) Then

    Dim v As Variant

    pProfile2.AllowedAuth = RTCAU_NTLM Or RTCAU_KERBEROS
		
    ' Enable Presence and Local storage.

    Dim pPresence2 As IRTCClientPresence2
    Set pPresence2 = pClient

    v = "local_presence_file.xml"

    Call pPresence2.EnablePresenceEx(pProfile2, v, 0)

    ' 
    ' Log on to the server with roaming.
    ' 
    Dim pProv2 As IRTCClientProvisioning2
    pProv2 = pClient

    Call pProv2.EnableProfileEx(pProfile2, _ 
                                RTCRF_REGISTER_ALL, _ 
                                RTCRMF_BUDDY_ROAMING Or _
                                RTCRMF_PRESENCE_ROAMING Or _
                                RTCRMF_PROFILE_ROAMING Or _ 
                                RTCRMF_WATCHER_ROAMING)

ElseIf (enType = RTCPFET_PROFILE_UPDATE) Then

    ' The profile was updated from the server.
    ' We may want to update the user interface based on this change.

End If