Pass PIC N(n) in safearray to COM object

Viewed 101

I am creating this safearray in MicroFocus Cobol (for pass to COM object):

           move VT-BSTR to w-vartype
           move 1 to w-dimension
           compute w-y = a-x * 2
           move w-y to cElements of w-saBound(1)
           move 0 to llBound of w-saBound(1)
           invoke OLESafeArray "new"
            using by value w-vartype w-dimension
            by reference w-saBound(1)
            returning w-accArray
           end-invoke
           move a-x to cElements of w-saBound(1)
           invoke OLESafeArray "new"
            using by value w-vartype w-dimension
            by reference w-saBound(1)
            returning w-modArray
           end-invoke

           initialize w-x
           perform varying w-Index from 0 by 1 until w-Index >= w-y
             add 1 to w-x
             move n'aaa' to acc-bank-acc-num
             invoke w-accArray "putString"
              using by reference w-Index
                    by value 68
                    by reference w-acc-num(w-x)
              returning w-hresult
             end-invoke
             add 1 to w-Index
             invoke w-accArray "putString"
              using by reference w-Index
                    by value 68
                    by reference w-acc-result(w-x)
              returning w-hresult
             end-invoke
           end-perform

           perform varying w-Index from 0 by 1 until w-Index >= a-x
             invoke w-modArray "putString"
              using by reference w-Index
                    by value 4
                    by reference w-acc-mod(w-Index + 1)
              returning w-hresult
             end-invoke
           end-perform

When I am passing PIC X(n) variables (in sample w-acc-num, w-acc-result, etc.) everything is OK. But I need to process Unicode strings, so data type must be PIC N(n). And then result in COM object (.NET C#) is bad, for example like this:

  • I am sending: "1072907036"
  • But in COM object I receive: "1\00\07\02\09\00\07\00\03\06\0"

I suppose, that problem is in type VT_BSTR, should I use VT_VARIANT instead? And if it so, how to properly use safearray of VT_VARIANTs? And I also returning this array back to COBOL.

1 Answers

VT_BSTR is a Unicode string. So I would expect the methods you call on the safe array to convert the pic x(..) to a Unicode BSTR. It will just take the PIC N Buffer and convert it.

If you have these chars as sbcs (single byte charset) then it should go across as a string and be converted to BSTR on the way.

If using N" " national literals then make sure you use NSYMBOL"NATIONAL" directive or the system could interpret as a DBCS Literal.

Related