Chapter 3: Creating a COM Object Using the Wizards

You need to read the chapters in this book in the order shown by the Tutorials map.

Overview

In this chapter, you use the Class and Method Wizards to create a COM object.

When you make an application into a COM object, you enable client applications to call it. Because COM deals with objects, the easiest way to prepare a COBOL application for deployment as a COM object is to write it as a set of inter-related object-oriented classes. But if you have an existing application written in traditional procedural COBOL, you can wrap each COBOL program in an object-oriented class - the client application calls the class's methods, which then call the procedural COBOL routines. Net Express has facilities to help create this wrapper class and register it as an COM object. They are the Class Wizard and the Method Wizard.

Preparation

If you have closed Net Express, reopen it. If any project window or other windows are open, close them.

Create a COM Object

To create a COM object:

  1. Ensure the OO COBOL toolbar is visible - click View > Dockable Windows and check OO COBOL.
  2. Select File > New > Class or on the OO COBOL toolbar to start the Class Wizard.
  3. On the first page of the Wizard, select COM component if you want to simply deploy your class as a COM object (see Figure 3-1), or COM transactional component if you want to make it a transactional component.

    The Class Wizard with COM Component Selected

    Figure 3-1: The Class Wizard with COM Component Selected

  4. On the remaining pages of the Wizard you specify further details such as the name for the executable file to contain the built COBOL class.
  5. Creating the class also creates a .reg file which you then run to register the class as a COM object. If you specify it is to be a remote object (capable of being called across a network, using DCOM), two .reg files are created.

You then create methods in the class, using on the OO COBOL toolbar to start the Method Wizard. The Wizard creates empty methods, for you to insert your code. You create one method for each business routine, and simply insert a line to call the business routine.

Before Continuing...

If you wish, you can call your COM object from a .NET managed code client application, which you write using Visual Studio. To see how to do this, continue at the chapter .NET Client for COM in your Interface Mapping Tutorials.

If you want to take a break first, you can close Net Express and/or the project - you will need to re-open them during the next chapter.


Copyright © 2006 Micro Focus (IP) Ltd. All rights reserved.