Reflection for IBM version 14.x
Reflection for UNIX and OpenVMS version 14.x
This technical note provides basic information to help programmers who are new to Reflection, or experienced VB programmers who are new to .NET, work with Reflection in a .NET environment. Information about using ActiveX control in this environment is also included.
Note the following:
- This technical note does not apply to Reflection 2014 or Reflection 2011.
For information on using Reflection 2014 with .NET, see
For information on using Reflection 2011 R3 with .NET, see
- Starting in version 12.0, the Reflection macro recorder will record commands using C# or VB.NET syntax. See KB 7021690 for details.
The Reflection COM Object
The Reflection API provides a COM object that is available to .NET programmers. COM objects can cause memory leaks in a .NET environment; however, Attachmate optimized the Reflection COM object to prevent memory leaks in both C# and VB.NET in Reflection version 11.0.3 or higher.
Getting Started with Reflection 14.x in .NET
To successfully program with Reflection in a .NET environment, you must add a reference to Reflection, instantiate the Reflection session object, and properly name the Reflection constants, and handle errors.
Add a Reference to the Reflection Library
In the Visual Studio .NET editing environment, add a reference to the Reflection product you wish to control in your application.
- In the Add Reference dialog box, click the COM tab. Reflection emulation products appear as follows:
Reflection for IBM 12.0 (or higher) Object Library
Reflection for ReGIS Graphics
Reflection for UNIX and OpenVMS
- Select one or more of the above applications.
Note: Ensure that you do not select the corresponding ActiveX Control Library.
Instantiate the Reflection Session Object
After you have added a reference to the proper Reflection library, you must instantiate the Reflection session object.
Public RHP as New Reflection1.Session
Public RIBM as New Reflection.Session
Public RRG as New Reflection4.Session
Public RUO as New Reflection2.Session
public Reflection1.Session RHP = new Reflection1.Session();
public Reflection.Session RIBM = new Reflection.Session();
public Reflection4.Session RRG = new Reflection4.Session();
public Reflection2.Session RUO = new Reflection2.Session();
Naming the Reflection Constants
In Visual Basic 6 or VBA, after adding a reference to Reflection, the compiler recognizes Reflection constants such as rcAllowKeystrokes or rcVTPF1key. To access Reflection constants in C# and VB.NET, all Reflection constants must be preceded by <Object>.Constants, <Object>.ControlCodes, or <Object>.TerminalKeys, as appropriate.
Example Using Reflection for UNIX and OpenVMS
Handling Reflection Errors
Examples for error handling are provided for both VB.NET and C#.
VB.NET Error Handling
In VB.NET, you can use either a Tryâ¦Catch block or the Visual Basic 6 On Error GoTo method for error handling.
The following example shows the Tryâ¦Catch block:
âYour Reflection code here
Catch ReflectionError As Exception
If you want to use the On Error GoTo method, and you used the Reflection macro recorder to record programs in Visual Basic 6, then you will need to edit the code. (Note: Reflection for RIBM does not record error handling code, so you must edit your script manually to include the error handling code.) In VB.NET, labels cannot be inside a With block, so you must move the With block and use MsgBox rather than .MsgBox. Compare the recorded code to the edited code in the examples below:
On Error GoTo ErrorHandler
.MsgBox Err.Description, vbExclamation + vbOKOnly
On Error GoTo ErrorHandler
MsgBox Err.Description, vbExclamation + vbOKOnly
C# Error Handling
To handle errors in C#, execute Reflection code in a tryâ¦catch block, as shown in the following example:
//Your Reflection code here
Sample code, Reflection.NET_Samples.zip, is available for you to download from the Download Library.
Known Issue â Windows 7 64-bit
When opening the .NET sample in Visual Studio 2010 on Windows 7 64-bit, you may receive an error message:
"Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))"
To resolve this issue, you must create an "x86" Build Configuration Platform setting in Visual Studio 2010 and then change the configuration setting from "Any CPU" to "x86." Follow these steps to create the "x86" configuration:
- Open the Visual Studio 2010 Configuration Manager.
- Click Platform > New.
- Select x86 as the "New platform."
- Click OK.
Now you can change the configuration from "Any CPU" to "x86."
Known Issue â Undefined Reflection Types and Constants
The code samples in Reflection.NET_Samples.zip were originally created for use with Reflection 13.0 and contain a reference to the Reflection type library included in Reflection 13.0. If you are using Reflection 14.0 or 14.1, Visual Studio may not be able to resolve the reference to the earlier version of the Reflection type library when the project is upgraded to Visual Studio 2010 format. Reflection types and constants may appear "undefined".
To fix this, on the Project menu in Visual Studio 2010, select the <project name> Properties, and on the References tab, remove the reference to the missing Reflection type library (Reflection 13.0). Then, add a reference to the current version of Reflection, and the project should build properly.
Using ActiveX Control
Reflection also provides an ActiveX control. The ActiveX control is useful when a programmer needs to provide a terminal screen on a Windows form or web page along with another application or a different data source. An example of this is a document viewer that opens a specific document on the form when a user clicks on that document in the terminal screen.
Add Reference to both Session and ActiveX Control
To use the Reflection ActiveX control you need to add a reference to the Reflection Library, as described above, and add a reference the Reflection ActiveX Control 1.0 Type Library appropriate for your application, for example Reflection for HP ActiveX Control 1.0 Type Library.
Add ActiveX Control to the Toolbox
To add Reflection's ActiveX control to your project, first, you need to add it to your Toolbox. In your .NET project, right-click the Toolbox and select Customize Toolbox. Select the appropriate ActiveX control to add to the toolbox.
Add ActiveX Control to the Form
Once added to the Toolbox, the Reflection ActiveX control can be added to the form like any other control.
Note: When you add the Reflection ActiveX control to a Windows form in your VB.NET project in Microsoft Visual Studio 2008 or 2005, you may experience one of the following problems:
- When attempting to add the control, it may not display in the form. You may also see an âUnable to get the window handleâ error. To resolve this issue, update to Visual Studio 2008 Service Pack 1 or higher.
- After successfully adding the control, when you click on the control, the design environment may become nonresponsive. To workaround this issue, temporarily click a different application window (such as Notepad). When you return to Visual Studio, responsiveness is restored.
Instantiate the Reflection Session within the ActiveX Control
The Reflection ActiveX control has only a few methods and properties that control Reflection. Reflection is controlled by instantiating the Reflection Session object within the ActiveX control.
Public RHP As Reflection1.Session
RHP = Me.AxR1winCtrl1.GetActiveSession()
Public RIBM as Reflection.Session
RIBM = Me.AxRibmCtrl1.GetActiveSession()
Public RRG As Reflection4.Session
RRG = Me.AxR4winCtrl1.GetActiveSession()
Public RUO As Reflection2.Session
RUO = Me.AxR2winCtrl1.GetActiveSession()
In C#, you need to cast the Reflection Session object explicitly when instantiating it.
public Reflection1.Session RHP
Reflection1.Session RHP = (Reflection1.Session)axR1winCtrl1.GetActiveSession();
public RIBM as Reflection.Session
Reflection.Session RIBM = (Reflection.Session)axRibmCtrl1.GetActiveSession()
public Reflection4.Session RRG
Reflection4.Session RRG = (Reflection4.Session)axR4winCtrl1.GetActiveSession();
public Reflection2.Session RUO
Reflection2.Session RUO = (Reflection2.Session)axR2winCtrl1.GetActiveSession();
In VB.NET you can use the Reflection OnEvent method to set up events in Reflection that call the .RaiseControlEvent method. RaiseControlEvent raises an event that can be processed in VB.NET in your form code.
Note: Use of Automation events in C# is supported in version 14.0.2 (service pack 2 or 2.1). For more information, please contact Attachmate Technical Support, https://support.microfocus.com/contact/.
Example Using Reflection for UNIX and OpenVMS