Previous Topic Next topic Print topic


Calling a Native COBOL COM Object, Using RCW

The runtime-callable-wrapper (RCW) is a .NET technique for COM interoperability. RCW wraps a COM object so that the .NET runtime system can call it. It effectively exposes a COM interface so that managed code can call it.

The runtime-callable-wrapper (RCW) is a .NET technique for COM interoperability. RCW wraps a COM object so that the .NET runtime system can call it. It effectively exposes a COM interface so that managed code can call it. For more background, see the Visual Studio Help topic Runtime Callable Wrapper.

RCW enables the COBOL CALL statement to call native COBOL that is packaged as a COM object.

Note: The COM object must have a type library for it to be usable in the .NET environment.

To call a native COBOL from managed code, first you package the COBOL as a COM object and then you register it. You then add the COM object as a reference in your project. When you build the project, the RCW is generated, thereby exposing the COM class as a managed proxy class. When you run the application, the managed code accesses the COBOL COM object running as a COM automation server.

The benefit of using RCW is that your managed program just sees the COM object as a managed class (and you get the benefit of IntelliSense). The .NET run-time system manages the data type manipulation to convert .NET types to COM types for you.

To call a native COBOL COM object

  1. Package the native COBOL as a COM object.

    Note that in .NET, COM objects must have a type library.

  2. Register the COM object using the command:
    regsvr32 myCOMObject.dll
  3. Add the COM object to your Visual COBOL project as a reference. To do this:
    1. Right-click References in Solution Explorer.
    2. Click Add reference.
    3. Browse to your COM object and select it.
  4. In your managed code, invoke the COM object in the same way as any other managed object. The following example invokes the Calculate method on the object theLoanCalculator:
    invoke theLoanCalculator::"Calculate"
Previous Topic Next topic Print topic