This topic demonstrates how to share an application process in a conversation using .NET managed code with Microsoft Lync 2010 SDK.

Prerequisites

For a list of prerequisites, see Walkthrough: Start an Instant Message Conversation .

Creating the Desktop Sharing Application

To create the desktop sharing application

  1. Sign in to Microsoft Lync 2010.

  2. In Microsoft Visual Studio development system, create a new Windows Forms application.

  3. Select .NET Framework 3.5 or 4.0 as the target framework. For more information, see the MSDN topic How to: Target a Specific .NET Framework.

  4. Add a reference to Microsoft.Lync.Model.

  5. In Form1.cs add the following using statement.

      Copy imageCopy Code
    using Microsoft.Lync.Model;
    using Microsoft.Lync.Model.Extensibility;
    
  6. In the Form1_Load event handler add the following code that performs the following tasks:

    1. Declares and instantiates a conversation context data dictionary.

    2. Gets an instance of Automationwhich will be called upon to start the conversation.

    3. Set the modes of the conversation to application sharing and instant messaging.

    4. Get the processes running on the local machine and choose the first running process.

    5. Set instant messaging and application sharing resource context for the conversation and then begin the conversation.

      Copy imageCopy Code
    // a) Create a dictionary object to contain
    AutomationModalitySettings data pairs. 
    Dictionary<AutomationModalitySettings, object>
    _ModalitySettings = new Dictionary<AutomationModalitySettings,
    object>();
    
    // b) Get the Automation object.
    Automation _Automation = LyncClient.GetAutomation();
    
    // c) Specify the conversation modes of application sharing and
    instant messaging.
    private AutomationModalities _ChosenMode =
    AutomationModalities.ApplicationSharing |
    AutomationModalities.InstantMessage;
    
    // d) Declare and instantiate an array of Process instances to hold
    all processes running on local computer.
    
    Process[] RunningProcesses =
    System.Diagnostics.Process.GetProcesses();
    Process runningProcess = RunningProcesses[0];
    
    //Get the selected Process Id and convert to int.
    uint selectedProcess = Convert.ToUInt32(runningProcess.Id);
    
    //Get the main window handle of the selected process and convert to
    int.
    uint selectedWindowHandle =
    Convert.ToUInt32(runningProcess.MainWindowHandle);
    
    //Add the process Id to the modality settings for the conversation.
    _ModalitySettings.Add(AutomationModalitySettings.SharedProcess,
    selectedProcess);
    
    //Add the main window handle to the modality settings for the
    conversation.
    _ModalitySettings.Add(AutomationModalitySettings.SharedWindow,
    selectedWindowHandle);
    
    //Adds text to toast and local user IMWindow text entry control.
    _ModalitySettings.Add(AutomationModalitySettings.FirstInstantMessage,
    "Hello Elise. I would like to share my first running process with
    you.");
    _ModalitySettings.Add(AutomationModalitySettings.SendFirstInstantMessageImmediately,
    true);
    
    
    //declare the string array
    string[] invitees = {″elise@contoso.com"};
    
    IAsyncResult ar =  _Automation.BeginStartConversation(
    					_ChosenMode
    					, invitees
    					, _ModalitySettings
    					, null
    					, null);
    
    //Block UI thread until conversation is started.
    _Automation.EndStartConversation(ar);
    
    
    
  7. Build and run the application. After the invited user accepts the process sharing request, the local machine's running instance of the first process is displayed within the remote Microsoft Lync 2010 conversation window .

If the program you want to share cannot be shared, see Error messages and troubleshootingfor information about process sharing problems.

See Also

Other Resources