我正在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-num
,w-acc-result
等中)时,一切正常。但是我需要处理Unicode字符串,因此数据类型必须为PIC N(n)
。然后导致COM对象(.NET C#)错误,例如:
我想这个问题属于VT_BSTR
类型,我应该改用VT_VARIANT
吗?如果是这样,如何正确使用VT_VARIANT
的safearray?而且我还将这个数组返回给COBOL。
答案 0 :(得分:1)
VT_BSTR是Unicode字符串。因此,我希望您在安全数组上调用的方法将pic x(..)转换为Unicode BSTR。它将只使用PIC N缓冲区并将其转换。
如果您将这些字符作为sbcs(单字节字符集)使用,则应将其作为字符串传递,并在此过程中将其转换为BSTR。
如果使用N“”国家文字,那么请确保使用NSYMBOL“ NATIONAL”指令,否则系统可以解释为DBCS Literal。