Skip to main content

I would like to be able to use our 32-bit installation of ACUCOBOL 9.2.1 to call a method from a non-GUI class in a .NET 4.0 DLL.

There are no sample programs in the sample directory that show an example of using the CREATE statement, so I tried to write my own. However, I can't get the COBOL in my minimal test to compile. Can anyone here help?

The C# code for the .NET DLL is in the file MyDLL.cs:

namespace MyNamespace {
    public class MyClass {
        public int getInt() {
            return 42;
        }
    }
}

I compiled this in 64-bit Windows 7 using what I think is the "any CPU" version of the C# compiler and framework:

C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319\\csc /t:library MyDLL.cs

The resulting DLL is named MyDLL.dll. I then used the 32-bit version of netdefgen to create a copybook called MyDLL.def:

      *  ACUCOBOL-GT Version 9.2.1 .NET Copy Book - Generated On 10/10/2013 2:52:07 PM
      *  Managed assembly, generated by 32-bit NetDefGen.exe

           OBJECT @ASSEMBLY
           NAME    "@MyDLL"
           VERSION "0.0.0.0"
           CULTURE "neutral"
           STRONG  "null"


      * FULLY-QUALIFIED-NAME MyNamespace.MyClass, MyDLL, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null

      * MyNamespace.MyClass
           NAMESPACE "MyNamespace"
           CLASS     "MyClass"
           MODULE    "MyDLL.dll"

           CONSTRUCTOR, 0, @CONSTRUCTOR1

      * [Class: MyClass] Int32 getInt()
           METHOD, 0, "@getInt"
           RETURNING "int", TYPE 3

The COBOL for the test program (MyCOBOL.cbl) is:

       IDENTIFICATION DIVISION.
       PROGRAM-ID.  TESTPROG.

       ENVIRONMENT DIVISION.
       CONFIGURATION SECTION.
       SPECIAL-NAMES.
           COPY "MyDLL.def".
           .

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       77  WS-NONGUI-HANDLE  HANDLE OF "@MyDll.MyNamespace.MyClass".
       77  WS-INT            PIC 9(5).

       PROCEDURE DIVISION.
           CREATE "@MyDLL"
             NAMESPACE IS "MyNamespace"
             CLASS-NAME IS "MyClass"
             HANDLE IS WS-NONGUI-HANDLE.

           INQUIRE WS-NONGUI-HANDLE "getInt" IN WS-INT
           DISPLAY "WS-INT: " WS-INT
           ACCEPT OMITTED
           
           GOBACK.

All of the files above are in the same directory:

C:\\Some\\Working\\Directory>dir /b
MyDLL.cs
MyDll.def
MyDLL.dll
MyCOBOL.cbl

I compiled the COBOL using  :

%PATH_TO_32BIT_ACU921%\\bin\\ccbl32 -Sp . MyCOBOL.cbl

The errors are:

MyCOBOL.cbl, line 21: 'getInt' must be a 'get' property or method of 'MyNamespac
e'
MyCOBOL.cbl, line 21: Verb expected, IN found

This doesn't make a whole lot of sense. I would have expected the compiler to look for a method of 'MyClass' rather than 'MyNamespace'.

What am I doing wrong?


#compilererrors
#.net

I would like to be able to use our 32-bit installation of ACUCOBOL 9.2.1 to call a method from a non-GUI class in a .NET 4.0 DLL.

There are no sample programs in the sample directory that show an example of using the CREATE statement, so I tried to write my own. However, I can't get the COBOL in my minimal test to compile. Can anyone here help?

The C# code for the .NET DLL is in the file MyDLL.cs:

namespace MyNamespace {
    public class MyClass {
        public int getInt() {
            return 42;
        }
    }
}

I compiled this in 64-bit Windows 7 using what I think is the "any CPU" version of the C# compiler and framework:

C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319\\csc /t:library MyDLL.cs

The resulting DLL is named MyDLL.dll. I then used the 32-bit version of netdefgen to create a copybook called MyDLL.def:

      *  ACUCOBOL-GT Version 9.2.1 .NET Copy Book - Generated On 10/10/2013 2:52:07 PM
      *  Managed assembly, generated by 32-bit NetDefGen.exe

           OBJECT @ASSEMBLY
           NAME    "@MyDLL"
           VERSION "0.0.0.0"
           CULTURE "neutral"
           STRONG  "null"


      * FULLY-QUALIFIED-NAME MyNamespace.MyClass, MyDLL, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null

      * MyNamespace.MyClass
           NAMESPACE "MyNamespace"
           CLASS     "MyClass"
           MODULE    "MyDLL.dll"

           CONSTRUCTOR, 0, @CONSTRUCTOR1

      * [Class: MyClass] Int32 getInt()
           METHOD, 0, "@getInt"
           RETURNING "int", TYPE 3

The COBOL for the test program (MyCOBOL.cbl) is:

       IDENTIFICATION DIVISION.
       PROGRAM-ID.  TESTPROG.

       ENVIRONMENT DIVISION.
       CONFIGURATION SECTION.
       SPECIAL-NAMES.
           COPY "MyDLL.def".
           .

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       77  WS-NONGUI-HANDLE  HANDLE OF "@MyDll.MyNamespace.MyClass".
       77  WS-INT            PIC 9(5).

       PROCEDURE DIVISION.
           CREATE "@MyDLL"
             NAMESPACE IS "MyNamespace"
             CLASS-NAME IS "MyClass"
             HANDLE IS WS-NONGUI-HANDLE.

           INQUIRE WS-NONGUI-HANDLE "getInt" IN WS-INT
           DISPLAY "WS-INT: " WS-INT
           ACCEPT OMITTED
           
           GOBACK.

All of the files above are in the same directory:

C:\\Some\\Working\\Directory>dir /b
MyDLL.cs
MyDll.def
MyDLL.dll
MyCOBOL.cbl

I compiled the COBOL using  :

%PATH_TO_32BIT_ACU921%\\bin\\ccbl32 -Sp . MyCOBOL.cbl

The errors are:

MyCOBOL.cbl, line 21: 'getInt' must be a 'get' property or method of 'MyNamespac
e'
MyCOBOL.cbl, line 21: Verb expected, IN found

This doesn't make a whole lot of sense. I would have expected the compiler to look for a method of 'MyClass' rather than 'MyNamespace'.

What am I doing wrong?


#compilererrors
#.net

I'm not an expert at this, but I believe the compiler is complaining that you are inquiring on a method, whereas it should be defined as a property.

 PROPERTY_GET, 0, "@getInt

              RETURNING, "BSTR", TYPE 8

While the example is a GUI example, the amortcontrol sample has a lot of information. C:\\Program Files (x86)\\Micro Focus\\Acucbl921\\AcuGT\\sample\\dotnet


I would like to be able to use our 32-bit installation of ACUCOBOL 9.2.1 to call a method from a non-GUI class in a .NET 4.0 DLL.

There are no sample programs in the sample directory that show an example of using the CREATE statement, so I tried to write my own. However, I can't get the COBOL in my minimal test to compile. Can anyone here help?

The C# code for the .NET DLL is in the file MyDLL.cs:

namespace MyNamespace {
    public class MyClass {
        public int getInt() {
            return 42;
        }
    }
}

I compiled this in 64-bit Windows 7 using what I think is the "any CPU" version of the C# compiler and framework:

C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319\\csc /t:library MyDLL.cs

The resulting DLL is named MyDLL.dll. I then used the 32-bit version of netdefgen to create a copybook called MyDLL.def:

      *  ACUCOBOL-GT Version 9.2.1 .NET Copy Book - Generated On 10/10/2013 2:52:07 PM
      *  Managed assembly, generated by 32-bit NetDefGen.exe

           OBJECT @ASSEMBLY
           NAME    "@MyDLL"
           VERSION "0.0.0.0"
           CULTURE "neutral"
           STRONG  "null"


      * FULLY-QUALIFIED-NAME MyNamespace.MyClass, MyDLL, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null

      * MyNamespace.MyClass
           NAMESPACE "MyNamespace"
           CLASS     "MyClass"
           MODULE    "MyDLL.dll"

           CONSTRUCTOR, 0, @CONSTRUCTOR1

      * [Class: MyClass] Int32 getInt()
           METHOD, 0, "@getInt"
           RETURNING "int", TYPE 3

The COBOL for the test program (MyCOBOL.cbl) is:

       IDENTIFICATION DIVISION.
       PROGRAM-ID.  TESTPROG.

       ENVIRONMENT DIVISION.
       CONFIGURATION SECTION.
       SPECIAL-NAMES.
           COPY "MyDLL.def".
           .

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       77  WS-NONGUI-HANDLE  HANDLE OF "@MyDll.MyNamespace.MyClass".
       77  WS-INT            PIC 9(5).

       PROCEDURE DIVISION.
           CREATE "@MyDLL"
             NAMESPACE IS "MyNamespace"
             CLASS-NAME IS "MyClass"
             HANDLE IS WS-NONGUI-HANDLE.

           INQUIRE WS-NONGUI-HANDLE "getInt" IN WS-INT
           DISPLAY "WS-INT: " WS-INT
           ACCEPT OMITTED
           
           GOBACK.

All of the files above are in the same directory:

C:\\Some\\Working\\Directory>dir /b
MyDLL.cs
MyDll.def
MyDLL.dll
MyCOBOL.cbl

I compiled the COBOL using  :

%PATH_TO_32BIT_ACU921%\\bin\\ccbl32 -Sp . MyCOBOL.cbl

The errors are:

MyCOBOL.cbl, line 21: 'getInt' must be a 'get' property or method of 'MyNamespac
e'
MyCOBOL.cbl, line 21: Verb expected, IN found

This doesn't make a whole lot of sense. I would have expected the compiler to look for a method of 'MyClass' rather than 'MyNamespace'.

What am I doing wrong?


#compilererrors
#.net

In my trivial example I could change the C# method to a property. However, in my intended use case, which is less trivial, I do want the ability to call a method. So I would like to see how that is done.

The following statement from the reference manual for ACUCOBOL 9.2.1 seems to imply that I must use the CREATE statement with my non-graphical .NET class -- but that the handle I get will be a handle to the assembly rather than to an object from my class:

"The CREATE statement creates a new instance of a non-graphical object such as a COM object or .NET assembly. Use it specifically for objects or assemblies that are not visual in nature. Use the Screen Section or DISPLAY statement to create an instance of a graphical .NET assembly or an ActiveX control."

The CREATE statement *does* take a CLASS-NAME. However, based on the error message from ccbl32, it seems that I really do have a handle to the assembly rather than a handle to an object of type MyClass.

On that basis, it looks like I would need to instantiate MyClass somehow, in order to be able to call that object's getInt method. But how? And why would the CREATE statement take a CLASS-NAME if it returns a handle to an assembly?

Your help so far is appreciated.


I would like to be able to use our 32-bit installation of ACUCOBOL 9.2.1 to call a method from a non-GUI class in a .NET 4.0 DLL.

There are no sample programs in the sample directory that show an example of using the CREATE statement, so I tried to write my own. However, I can't get the COBOL in my minimal test to compile. Can anyone here help?

The C# code for the .NET DLL is in the file MyDLL.cs:

namespace MyNamespace {
    public class MyClass {
        public int getInt() {
            return 42;
        }
    }
}

I compiled this in 64-bit Windows 7 using what I think is the "any CPU" version of the C# compiler and framework:

C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319\\csc /t:library MyDLL.cs

The resulting DLL is named MyDLL.dll. I then used the 32-bit version of netdefgen to create a copybook called MyDLL.def:

      *  ACUCOBOL-GT Version 9.2.1 .NET Copy Book - Generated On 10/10/2013 2:52:07 PM
      *  Managed assembly, generated by 32-bit NetDefGen.exe

           OBJECT @ASSEMBLY
           NAME    "@MyDLL"
           VERSION "0.0.0.0"
           CULTURE "neutral"
           STRONG  "null"


      * FULLY-QUALIFIED-NAME MyNamespace.MyClass, MyDLL, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null

      * MyNamespace.MyClass
           NAMESPACE "MyNamespace"
           CLASS     "MyClass"
           MODULE    "MyDLL.dll"

           CONSTRUCTOR, 0, @CONSTRUCTOR1

      * [Class: MyClass] Int32 getInt()
           METHOD, 0, "@getInt"
           RETURNING "int", TYPE 3

The COBOL for the test program (MyCOBOL.cbl) is:

       IDENTIFICATION DIVISION.
       PROGRAM-ID.  TESTPROG.

       ENVIRONMENT DIVISION.
       CONFIGURATION SECTION.
       SPECIAL-NAMES.
           COPY "MyDLL.def".
           .

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       77  WS-NONGUI-HANDLE  HANDLE OF "@MyDll.MyNamespace.MyClass".
       77  WS-INT            PIC 9(5).

       PROCEDURE DIVISION.
           CREATE "@MyDLL"
             NAMESPACE IS "MyNamespace"
             CLASS-NAME IS "MyClass"
             HANDLE IS WS-NONGUI-HANDLE.

           INQUIRE WS-NONGUI-HANDLE "getInt" IN WS-INT
           DISPLAY "WS-INT: " WS-INT
           ACCEPT OMITTED
           
           GOBACK.

All of the files above are in the same directory:

C:\\Some\\Working\\Directory>dir /b
MyDLL.cs
MyDll.def
MyDLL.dll
MyCOBOL.cbl

I compiled the COBOL using  :

%PATH_TO_32BIT_ACU921%\\bin\\ccbl32 -Sp . MyCOBOL.cbl

The errors are:

MyCOBOL.cbl, line 21: 'getInt' must be a 'get' property or method of 'MyNamespac
e'
MyCOBOL.cbl, line 21: Verb expected, IN found

This doesn't make a whole lot of sense. I would have expected the compiler to look for a method of 'MyClass' rather than 'MyNamespace'.

What am I doing wrong?


#compilererrors
#.net

Changing the COBOL source code as follows allowed it to compile:

     *    INQUIRE WS-NONGUI-HANDLE "getInt" IN WS-INT

          MODIFY WS-NONGUI-HANDLE "getInt"() GIVING WS-INT

I guess the INQUIRE verb is only valid for fields or properties, which is consistent with your initial reply.

I did encounter a runtime error on the MODIFY statement, but since the compiler error per se is resolved, I'll mark this question as answered.