Controlling Reflection 14.x from Other Applications Using COM/Automation

  • 7021740
  • 23-Mar-2015
  • 31-Mar-2018


Reflection for IBM version 14.x or earlier
Reflection for HP version 14.x or earlier
Reflection for UNIX and OpenVMS version 14.x or earlier


Reflection can be controlled from other applications through a set of standard protocols called Automation (also known as OLE Automation or COM). This technical note provides steps and examples on how to do this.

Note the following:

  • Information in this note is not intended for Reflection Desktop/2014/2011. Using methods detailed here may result in errors.
  • Newer Automation and.NET APIs are supported in Reflection Desktop/2014/2011, and are recommended for new projects. For more information, see KB 7021508.



Reflection’s COM API (previously known as Automation or OLE Automation) provides a way to control Reflection from other applications, such as Microsoft Office products or a Visual Basic project. You can use this API to send instructions to Reflection and extract host data.

For example, from Microsoft Word or Excel, you can launch a Reflection session, log onto a host, and copy screen data to the current document. In this situation, Reflection is the object (or server) that is being manipulated by Word, which is the controller (or client).

Reflection's COM/Automation support is provided by Visual Basic for Applications (VBA) and Reflection's methods and properties. When you want to communicate with Reflection from another application, create a Reflection object and use Reflection's methods and properties in the other application's programming environment.

Controlling Reflection from Other Applications

The following steps are guidelines for controlling Reflection from other applications that use COM/Automation:

  1. In the procedure you are writing in the other application, dimension an object variable for the Reflection object. For late binding use the following statement:
Dim MyReflectionObject As Object

For early binding, use one of the following statements, depending on the Reflection product or host/terminal type you are using:

Dim MyObject As Reflection.Session 'Reflection for IBM
Dim MyObject As Reflection1.Session 'Reflection for HP
Dim MyObject As Reflection2.Session 'Reflection for UNIX and OpenVMS
Dim MyObject As Reflection4.Session 'Reflection for ReGIS Graphics
  1. Use Set to assign a Reflection object to the object variable. You can create a new instance of Reflection at this time, or attach to an existing Reflection object.
    • Use CreateObject to create a new Reflection object. (See Using CreateObject for more information.)
    • Use GetObject to attach to an existing Reflection object. (See Using GetObject for more information.)

For example, this statement creates a new Reflection for IBM object:

Set MyReflectionObject = CreateObject("ReflectionIBM.Session")
  1. Use the Reflection object you just created to access Reflection's methods and properties. Refer to the appropriate Language Reference for your product or host/terminal type:

Note: The CreateObject function launches Reflection, but does not make the application visible. If you want Reflection to be visible while the other application uses it, use Reflection's Visible property. For example:

MyReflectionObject.Visible = True

Using CreateObject

Use CreateObject to create a new instance of an Automation application. CreateObject takes one argument of the form (AppName.ObjectType). AppName is the name of an application and ObjectType specifies the object to create. Many applications support several objects. Reflection has only one object (Session), and all Reflection methods and properties act on this object.

The following examples show how to use CreateObject to create a Reflection object for different Reflection products:

To create a Reflection for HP object:

Dim ReflectionHP As Reflection1.Session
Set ReflectionHP = CreateObject("Reflection1.Session")

To create a Reflection for UNIX and OpenVMS object:

Dim ReflectionUD As Reflection2.Session
Set ReflectionUD = CreateObject("Reflection2.Session")

To create a Reflection for ReGIS Graphics object:

Dim ReflectionGraphics As Reflection4.Session
Set ReflectionGraphics = CreateObject("Reflection4.Session")

To create a Reflection for IBM object:

Dim ReflectionIBM As Reflection.Session
Set ReflectionIBM = CreateObject("ReflectionIBM.Session")

Using GetObject

GetObject returns a reference to an object. With most applications, you can specify a file name to identify the object. For example, you can access an open Word document like this:

Dim Word As Object
Set Word = GetObject("C:\Mypath\Mydoc.doc")

To use GetObject to access a Reflection session, you can use two different strategies. GetObject supports two arguments; the first argument, pathname, specifies a path and file name (for most applications); the second specifies an application name and object type. The following examples show how to use each of these arguments to attach to a Reflection session:

Attaching to Reflection Using the OLE Server Name

This technique uses the first argument to the GetObject function. The value you use for this argument should be the OLE Server name for that session. This name is specified in Reflection using the OLEServerName property. Because you can specify a unique OLE server name for every Reflection session, this technique allows you to identify a particular Reflection session even if multiple sessions are active. The default values for this property are:

Default Value
Reflection for HP
Reflection for UNIX and OpenVMS
Reflection for ReGIS Graphics
Reflection for IBM

The following example shows how to attach to an instance of Reflection for ReGIS Graphics using the default OLEServerName value:

Dim ReflectionReGIS As Object
Set ReflectionReGIS = GetObject("R4WIN")

Attaching to Reflection Using the Session Object

This technique uses the second argument to the GetObject function, which has the format "AppName.ObjectType". The application name for Reflection products are:

Reflection for HP
Reflection for UNIX and OpenVMS
Reflection for ReGIS Graphics
Reflection for IBM

All Reflection products support a single object called Session.

The following example shows how to attach to Reflection for IBM. The comma is needed to indicate that the first argument is being omitted.

Dim RibmObject As Object
Set RibmOjbect = GetObject(, "ReflectionIBM.Session")

This technique works well if there is only one session running for any given Reflection product. If there are multiple Reflection sessions running, using this techniques makes the attachment to an arbitrary instance of Reflection.

Note: If you include an empty string for the first argument, GetObject will open the specified application. For example, these commands create a new instance of Reflection for HP:

Dim ReflectionHP As Object
Set ReflectionHP = GetObject("", "Reflection1.Session")

Example: Creating a Reflection for IBM Object

This example creates a new instance of Reflection for IBM and uses a Reflection property to change the new Reflection window title. (See Using CreateObject for sample code that shows how to create instances of other Reflection products.) You can use this macro in Reflection to create a new Reflection session, or from another application using COM/Automation:

Sub CreateReflectionObject ()

'Declare the Reflection Object
Dim Ribm As Reflection.Session

'Create a new instance of Reflection for IBM
Set Ribm = CreateObject("ReflectionIBM.Session")

'Make Reflection visible
Ribm.Visible = True

'Use the Caption property to change the Reflection window title
Ribm.Caption = "Automation Demonstration"

End Sub

Additional Information

Legacy KB ID

This document was originally published as Attachmate Technical Note 2787.