CCW によるネイティブ COBOL からの .NET クラスの呼び出し

CCW (COM callable-wrapper; COM 呼び出し可能ラッパー) は、.NET で提供されている COM 相互運用機能の 1 つです。CCW でマネージ コードを COM オブジェクトとしてラップすると、ネイティブ コードから、他の COM オブジェクトと同様に呼び出すことができます。

つまり、あらゆる言語の .NET マネージ クラスが COM インターフェイスとして公開されます。詳しい背景情報については、Visual Studio のヘルプの「COM 呼び出し可能ラッパー」を参照してください。

.NET クラスを COM オブジェクトとして公開するには、クラスが COM 相互運用機能に登録されるように、プロジェクトを構成する必要があります。プロジェクトをビルドするとこのクラスが登録されて、ネイティブ COBOL 側で利用できるようになります。

.NET クラス内で定義および実装されたすべてのパブリック メソッドが、COM インターフェイスとして公開されます。COM クライアント アプリケーションは、これらのメソッドを、COM オブジェクトのメソッドであるかのように呼び出すことができます。

ネイティブ COBOL から .NET クラスを呼び出すには

  1. In Visual Studio, open the project containing the .NET class to expose, by clicking File > Open > Project and browsing to the project.
  2. Click Project > myProject Properties.
  3. On the COBOL tab, click Advanced, and check Register for COM interop.

    The native client can now invoke methods in the .NET class as if it was any other COM object, by using the COM programmatic ID of the .NET class. This ID is defined as DefaultNamespace.Class. Where the default namespace, DefaultNamespace, is defined on the Application tab in the project properties and is by default set to the name of the project.

    For example, a native COBOL client can invoke the .NET class called ManagedCOM, as follows:

    class ManagedCOM as "$OLE$COMDemo.ManagedCOM"

公開された .NET クラスをネイティブ COBOL から呼び出すには

ネイティブ COBOL から .NET クラスを COM オブジェクトであるかのように呼び出すには、次の要素をコードに追加します。

  1. Set the Checker directive OOCTRL(+P) in your program:
    $SET OOCTRL(+P)

    This checker directive enables the run-time system to map from COBOL data types to COM data types.

  2. Map each COM class to an OO COBOL proxy class in the CLASS-CONTROL paragraph. Give the COM class an OO COBOL class-name, and specify that it is in the COM domain, using a statement of the form:
    class-name IS CLASS "$OLE$windows-registry-name"

    where windows-registry-name is one of the following:

    • the ProgID for the server
    • the CLSID for the server

    The ProgID and CLSID are defined in the Windows registry.

  3. Create an instance of the OO COBOL COM class.

    Send the message "new" to the OO COBOL proxy class. This starts the COM server if it is not already running. You are returned an OO COBOL handle which you can use to send messages to the COM server.

  4. Send messages to the COM server.
  5. To access properties, prefix the property name with "Set" to set a property or "Get" to retrieve a property.

    When setting a property, pass a single parameter. When getting a property the value is returned as the RETURNING parameter.