COM Interface C# Sample

This sample executes a task and displays the results. It contains a single task called Task, and a single input and output called respectively, Input and Output. The task is defined in a sample task file generated in Task Builder for Screens.

using System;
using System.Xml;
using SCREENCONNECTORLib;

namespace CSharpApp
{
  class Test
  {
    [STAThread]
    static void Main(string[] args)
    {
      ScreenConnector connector = null;

      try
      {
        //Instantiate and initialize the connector
        connector = new ScreenConnector();
       
        //Open a task file and execute a task
        connector.open("C:\\Program Files\\Attachmate\\EAI\\recordings\\Test\\connector\\Test.xml");
        connector.execute("Task","<ScreenInputs><Input>data</Input></ScreenInputs>");

        //Parse the outputs(<ScreenOutputs><Output>result</Output></ScreenOutputs>)
        XmlDocument outputXML = new XmlDocument();
        outputXML.LoadXml(connector.getData());
        String result = outputXML.GetElementsByTagName("Output").Item(0).InnerText;

        //Display the results
        System.Console.Out.WriteLine(result);
      }
      catch (Exception xx)
      {
        System.Console.Error.WriteLine(xx.ToString());
      }
      finally
      {
        //Close the connector and clean up
        try { connector.close(); } catch (Exception xx)  {}
      }
    }
  }
}
Related Topics
Bullet Using Tasks in Your Applications, Overview
Bullet Sample Task File
Bullet Building Applications Using Native Win32 Technologies
Bullet COM Interface API Reference
  Attachmate