Quantcast
Channel: Visual COBOL - Forum - Recent Threads
Viewing all articles
Browse latest Browse all 4356

RE: How to pass parameters from native to managed

$
0
0

When you are calling a managed code application from native code you are using the COM library support which has been retained from the Net Express product. This documentation is supplied in Visual COBOL in the separate help file, nxrclr.chm, which is installed in the Help folder of your installation. The default location is %ProgramFiles(x86)%\Micro Focus\Visual COBOL for Visual Studio 2012\Help.

It can also be found here

From the native support the run-time converts the appropriate data types into COM data types and then passes these to the COM interop layer of the managed program which converts them into managed types.

PIC X or group items are passed as BSTR's and are received as System.String in the managed code.
Numeric items are coerced into the appropriate type and are received as the same type.

The following is a simple example of passing some of these types:

native client program:

      $set ooctrl(+p)
      *----------------------------------------------------------------*
      *                    VCCOMClient                                 *
      *                                                                *
      * This program will create an instance of the VCCOMServer class  *
      * and then call its methods.                                     *
      *                                                                *
      * Before this can be done you must register the VCCOMServer class*
      * for use with COM by using Visual Studio 2010 to open up the    *
      * solution C:\VCCOMDemo\VCCOMServer\VCCOMServer\VCCOMServer.sln  *
      * and then select Rebuild Solution from the Build menu.          *
      *----------------------------------------------------------------*
       id division.
       program-id.  VCCOMClient.
       class-control.
           VCCOMServer is class "$OLE$VCCOMServer.VCCOMServer".
       working-storage section.
       01 anInstance    object reference.
       01 aString       pic x(50)   value spaces.
       01 anInteger     pic x(4) comp-5   value 0.
       01 aFloat        comp-2 value 0.
       01 aGroup.
          05 CustName    pic x(20).
          05 CustCompany pic x(20).
          05 CustInteger pic x(4) comp-5.
          05 CustDecimal pic s9(4)v99.

       procedure division.

           invoke VCCOMServer "new" returning anInstance
           invoke anInstance "testVCstring" using aString
           display aString

           invoke anInstance "testVCint" using anInteger
           display anInteger

           invoke anInstance "testVCFloat" using aFloat
           display aFloat

           invoke anInstance "testVCGroup" using aGroup
           display CustName
           display CustCompany
           display CustInteger
           display CustDecimal

           stop run.

managed COM server:

       identification division.
       interface-id. InterfaceDef as "IVCCOMServer".
       environment division.
       repository.           
           
       method-id. testVCstring public.
       local-storage section.       
       procedure division using lnkString as string.
       end method.
       
       method-id testVCint public.
       local-storage section.
       procedure division using lnkInt as binary-long.
       end method.
       
       method-id testVCFloat public.
       local-storage section.
       procedure division using lnkFloat as float-long.
       end method.
       
       method-id testVCGroup public.
       local-storage section.
       procedure division using lnkString as string.
       end method.    
       
       end interface InterfaceDef.

       class-id VCCOMServer.VCCOMServer implements type IVCCOMServer.
       working-storage section.

       method-id testVCstring.
       local-storage section.
       procedure division using lnkString as string.
	       move "From method testVCstring" to lnkString
           goback.
       end method.

       method-id testVCint public.
       local-storage section.
       procedure division using lnkInt as binary-long.
           move 50 to lnkInt
           goback.
       end method.
       
       method-id testVCFloat public.
       local-storage section.
       procedure division using lnkFloat as float-long.
           move 123.75 to lnkFloat
           goback.
       end method.
       
       method-id testVCGroup public.
       local-storage section.
       01 lnkGroup.
          05 lnkName    pic x(20).
          05 lnkCompany pic x(20).
          05 lnkInteger pic x(4) comp-5.
          05 lnkDecimal pic s9(4)v99.
       procedure division using lnkString as string.
           
           move "Chris Glazier" to lnkName
           move "Micro Focus" to lnkCompany
           move 20 to lnkInteger
           move -987.12 to lnkDecimal
           set lnkString to lnkGroup
           goback.
       end method.    
       end class.

Viewing all articles
Browse latest Browse all 4356

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>