CreateApplication() Method

Creates an application that represents the instance of Reflection that was just started by you, or a Reflection instance running at the default IPC channel (if the Reflection instance is the first instance started manually).
Public Overloads Shared Function CreateApplication() As Application
Dim value As Application
value = MyReflection.CreateApplication()
public static Application CreateApplication()

Return Value

An Application object.
This sample gets a handle to an application that represents the first instance of Reflection started manually. Then it gets a handle to a demo session and gets some text from a session screen. Before running this sample, make sure the demoSession.rd3x session is running in a workspace
//This sample gets the Terminal control of a running session.
//Before you run this sample, make sure the session used in GetControlsByFilePath()
//is running in a Reflection workspace. If more than one instance of Reflection is running,
//the session must be running in the first instance that was started.
using System;
using System.Collections.Generic;
using System.Text;
using Attachmate.Reflection.Framework;
using Attachmate.Reflection.Emulation.IbmHosts;
namespace ConnectToASession
    class Program
        static void Main(string[] args)
            //Get a handle to an application that represents the first instance of Reflection started manually.
            //For production code, use a try catch block here to handle a System Application Exception thrown
            //if the app isn't running.
            Application app = MyReflection.CreateApplication();

            //Get the terminal from the session document file path.
            string sessionPath = Environment.GetEnvironmentVariable("USERPROFILE") + @"\Documents\Micro Focus\Reflection\demoSession.rd3x";
            object[] terminals = app.GetControlsByFilePath(sessionPath);

            //Check to make sure the session is running.
            if (terminals != null && terminals.Length > 0)
                //Get a screen and then get some text from the screen.
                IIbmTerminal terminal = (IIbmTerminal)terminals[0];
                IIbmScreen screen = terminal.Screen;
                string text = screen.GetText(18, 2, 48);
                Console.WriteLine("No such control exists. Check to make sure that the session from the file is running.");

See Also