Highlighted
Absent Member.
Absent Member.
1196 views

DLL made in VB 6 (COM+) called from Visual Cobol

Jump to solution

[Migrated content. Thread originally posted on 02 November 2011]

Good morning,

I need to call a DLL (COM) using input parametes (array as variant) from VISUAL COBOL.
This DLL is installed in Server Transaction.

Here I post code in Visual Basic 6, How can I do the same call in VISUAL COBOL.

Dim objService as Object
Dim arrRpta as Variant
Dim arrData() as Variant

ArrData(1, 1)="001"
ArrData(2, 1)="Jack Smith"
ArrData(3, 1)="Married"
ArrData(4, 1)="10-12-1978"
ArrData(5, 1)=1500

ArrData(1, 2)="002"
ArrData(2, 2)="Mary Harrison"
ArrData(3, 2)="Married"
ArrData(4, 2)="07-08-1980"
ArrData(5, 2)=3500

Set objService = CreateObject("Customer.clsCustomer")
arrRpta = objServicio.CustomerSave(ArrData)

msgbox arrRpta(1,1) --"Sucess" o "failure"

Thanks,

Manuel
0 Likes
1 Solution

Accepted Solutions
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: DLL made in VB 6 (COM+) called from Visual Cobol

Jump to solution
The following example shows how this could be done in a native Visual COBOL program.
This example is just for reference as I cannot test it without the actual VB program.


      $set ooctrl(+p)
       program-id. testsafearray.
       object section.
       class-control.
           OleSafeArray is class "olesafea"
           OLEVariant is class "olevar"
           CustomerClass is class "$OLE$Customer.clsCustomer"
           .
       working-storage section.
       copy "mfole.cpy".
       copy "olesafea.cpy".
       01 objService           object reference.
       01 saBound              SAFEARRAYBOUND occurs 2.
       01 arrData              object reference.
       01 myvarType            pic 9(4) comp-5.
       01 dimensions           pic x(4) comp-5.
       01 theStringLength      pic 9(9) comp-5.
       01 theString            pic x(20) value spaces.
       01 iIndices.
          05 iIndex            pic 9(9) comp-5 occurs 2 times.
       01 ret-code             pic 9(9) comp-5 value zeroes.
       01 v                    VARIANT.
       01 theVariantObj        object reference.
       01 arrRpta              object reference.
       procedure division.
      *>---Set up the data type as a Variant. VT-VARIANT
      *>   is the COM data type for a VARIANT, defined in
      *>   MFOLE.CPY.
           move VT-VARIANT to myvarType
      *>---Set the array up as 2-dimensional
           move 2 to dimensions
      *>---Define this as a 5 by 2 array,with lower bounds
      *>   of 1. (The lower bound is the index of the first
      *>   element in a dimension)
           move 5 to cElements of saBound(1) *>cElements is
                                             *>a subitem of
                                             *>type SAFEARRAY,
                                             *>for setting
                                             *>dimension size
           move 1 to llBound of saBound(1)   *>llBound is
                                             *>a subitem of
                                             *>type SAFEARRAY,
                                             *>for setting
                                             *>dimension
                                             *> lower bounds
           move 2 to cElements of saBound(2)
           move 1 to llBound of saBound(2)
           invoke OleSafeArray "new" using
                                 by value myvarType
                                 by value dimensions
                                 by reference saBound(1)
                                 returning arrData

            move 1 to iIndex(1)
            move 1 to iIndex(2)
            move "001" to theString
            move 3 to theStringLength
            perform 100-put-string-in-safearray

            move 2 to iIndex(1)
            move 1 to iIndex(2)
            move "Jack Smith" to theString
            move 10 to theStringLength
            perform 100-put-string-in-safearray

            move 3 to iIndex(1)
            move 1 to iIndex(2)
            move "Married" to theString
            move 7 to theStringLength
            perform 100-put-string-in-safearray

            move 4 to iIndex(1)
            move 1 to iIndex(2)
            move "10-12-1978" to theString
            move 10 to theStringLength
            perform 100-put-string-in-safearray

            move zeroes to v
            move 1500 to VARIANT-VT-I4 of v
            move VT-I4 to VARIANT-vartype of v
            invoke oleVariant "newwithData" using v
               returning theVariantObj
            end-invoke

            move 5 to iIndex(1)
            move 1 to iIndex(2)

            invoke arrData "putVariantAsObject"
               using by reference iIndices
                     by reference theVariantObj
               returning ret-code
            end-invoke

            move 1 to iIndex(1)
            move 2 to iIndex(2)
            move "002" to theString
            move 3 to theStringLength
            perform 100-put-string-in-safearray

            move 2 to iIndex(1)
            move 2 to iIndex(2)
            move "Mary Harrison" to theString
            move 13 to theStringLength
            perform 100-put-string-in-safearray

            move 3 to iIndex(1)
            move 2 to iIndex(2)
            move "Married" to theString
            move 7 to theStringLength
            perform 100-put-string-in-safearray

            move 4 to iIndex(1)
            move 2 to iIndex(2)
            move "07-08-1980" to theString
            move 10 to theStringLength
            perform 100-put-string-in-safearray

            move zeroes to v
            move 3500 to VARIANT-VT-I4 of v
            move VT-I4 to VARIANT-vartype of v
            invoke oleVariant "newwithData" using v
               returning theVariantObj
            end-invoke

            move 5 to iIndex(1)
            move 2 to iIndex(2)

            invoke arrData "putVariantAsObject"
               using by reference iIndices
                     by reference theVariantObj
               returning ret-code
            end-invoke

            invoke CustomerClass "New" returning objService
            invoke objService "CustomerSave" using ArrData
               returning arrRpta
            end-invoke.
            stop run.

      *----------------------------------------------------------------*

       100-put-string-in-safearray.

            invoke arrData "putStringasVariant"
               using by reference iIndices
                     by value theStringLength
                     by reference theString
               returning ret-code
            end-invoke.

View solution in original post

0 Likes
3 Replies
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: DLL made in VB 6 (COM+) called from Visual Cobol

Jump to solution
You can but HOW you do it depends on if you wish to use native COBOL or managed COBOL to do the call.

Which one are you using?

Thanks.
0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: DLL made in VB 6 (COM+) called from Visual Cobol

Jump to solution
The following example shows how this could be done in a native Visual COBOL program.
This example is just for reference as I cannot test it without the actual VB program.


      $set ooctrl(+p)
       program-id. testsafearray.
       object section.
       class-control.
           OleSafeArray is class "olesafea"
           OLEVariant is class "olevar"
           CustomerClass is class "$OLE$Customer.clsCustomer"
           .
       working-storage section.
       copy "mfole.cpy".
       copy "olesafea.cpy".
       01 objService           object reference.
       01 saBound              SAFEARRAYBOUND occurs 2.
       01 arrData              object reference.
       01 myvarType            pic 9(4) comp-5.
       01 dimensions           pic x(4) comp-5.
       01 theStringLength      pic 9(9) comp-5.
       01 theString            pic x(20) value spaces.
       01 iIndices.
          05 iIndex            pic 9(9) comp-5 occurs 2 times.
       01 ret-code             pic 9(9) comp-5 value zeroes.
       01 v                    VARIANT.
       01 theVariantObj        object reference.
       01 arrRpta              object reference.
       procedure division.
      *>---Set up the data type as a Variant. VT-VARIANT
      *>   is the COM data type for a VARIANT, defined in
      *>   MFOLE.CPY.
           move VT-VARIANT to myvarType
      *>---Set the array up as 2-dimensional
           move 2 to dimensions
      *>---Define this as a 5 by 2 array,with lower bounds
      *>   of 1. (The lower bound is the index of the first
      *>   element in a dimension)
           move 5 to cElements of saBound(1) *>cElements is
                                             *>a subitem of
                                             *>type SAFEARRAY,
                                             *>for setting
                                             *>dimension size
           move 1 to llBound of saBound(1)   *>llBound is
                                             *>a subitem of
                                             *>type SAFEARRAY,
                                             *>for setting
                                             *>dimension
                                             *> lower bounds
           move 2 to cElements of saBound(2)
           move 1 to llBound of saBound(2)
           invoke OleSafeArray "new" using
                                 by value myvarType
                                 by value dimensions
                                 by reference saBound(1)
                                 returning arrData

            move 1 to iIndex(1)
            move 1 to iIndex(2)
            move "001" to theString
            move 3 to theStringLength
            perform 100-put-string-in-safearray

            move 2 to iIndex(1)
            move 1 to iIndex(2)
            move "Jack Smith" to theString
            move 10 to theStringLength
            perform 100-put-string-in-safearray

            move 3 to iIndex(1)
            move 1 to iIndex(2)
            move "Married" to theString
            move 7 to theStringLength
            perform 100-put-string-in-safearray

            move 4 to iIndex(1)
            move 1 to iIndex(2)
            move "10-12-1978" to theString
            move 10 to theStringLength
            perform 100-put-string-in-safearray

            move zeroes to v
            move 1500 to VARIANT-VT-I4 of v
            move VT-I4 to VARIANT-vartype of v
            invoke oleVariant "newwithData" using v
               returning theVariantObj
            end-invoke

            move 5 to iIndex(1)
            move 1 to iIndex(2)

            invoke arrData "putVariantAsObject"
               using by reference iIndices
                     by reference theVariantObj
               returning ret-code
            end-invoke

            move 1 to iIndex(1)
            move 2 to iIndex(2)
            move "002" to theString
            move 3 to theStringLength
            perform 100-put-string-in-safearray

            move 2 to iIndex(1)
            move 2 to iIndex(2)
            move "Mary Harrison" to theString
            move 13 to theStringLength
            perform 100-put-string-in-safearray

            move 3 to iIndex(1)
            move 2 to iIndex(2)
            move "Married" to theString
            move 7 to theStringLength
            perform 100-put-string-in-safearray

            move 4 to iIndex(1)
            move 2 to iIndex(2)
            move "07-08-1980" to theString
            move 10 to theStringLength
            perform 100-put-string-in-safearray

            move zeroes to v
            move 3500 to VARIANT-VT-I4 of v
            move VT-I4 to VARIANT-vartype of v
            invoke oleVariant "newwithData" using v
               returning theVariantObj
            end-invoke

            move 5 to iIndex(1)
            move 2 to iIndex(2)

            invoke arrData "putVariantAsObject"
               using by reference iIndices
                     by reference theVariantObj
               returning ret-code
            end-invoke

            invoke CustomerClass "New" returning objService
            invoke objService "CustomerSave" using ArrData
               returning arrRpta
            end-invoke.
            stop run.

      *----------------------------------------------------------------*

       100-put-string-in-safearray.

            invoke arrData "putStringasVariant"
               using by reference iIndices
                     by value theStringLength
                     by reference theString
               returning ret-code
            end-invoke.

View solution in original post

0 Likes
Highlighted
Absent Member.
Absent Member.

RE: DLL made in VB 6 (COM+) called from Visual Cobol

Jump to solution
Chris,
I appreciate your support, let me review your example with my team. Thanks a lot.
Manuel
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.