将safearray中的PIC N(n)传递给COM对象

时间:2019-06-28 14:02:30

标签: c# .net com cobol

我正在MicroFocus Cobol中创建此safearray(用于传递给COM对象):

           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

当我传递PIC X(n)变量(在示例w-acc-numw-acc-result等中)时,一切正常。但是我需要处理Unicode字符串,因此数据类型必须为PIC N(n)。然后导致COM对象(.NET C#)错误,例如:

  • 我要发送:“ 1072907036”
  • 但是在COM对象中,我收到:“ 1 \ 00 \ 07 \ 02 \ 09 \ 00 \ 07 \ 00 \ 03 \ 06 \ 0”

我想这个问题属于VT_BSTR类型,我应该改用VT_VARIANT吗?如果是这样,如何正确使用VT_VARIANT的safearray?而且我还将这个数组返回给COBOL。

1 个答案:

答案 0 :(得分:1)

VT_BSTR是Unicode字符串。因此,我希望您在安全数组上调用的方法将pic x(..)转换为Unicode BSTR。它将只使用PIC N缓冲区并将其转换。

如果您将这些字符作为sbcs(单字节字符集)使用,则应将其作为字符串传递,并在此过程中将其转换为BSTR。

如果使用N“”国家文字,那么请确保使用NSYMBOL“ NATIONAL”指令,否则系统可以解释为DBCS Literal。