2

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
  • Are you sending strings of binary data? I thought COBOL only dealt with strings. You com object looks like binary data. Commented Jun 28, 2019 at 14:41

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

4 Comments

Please is there any list of methods which could be called upon safearray? I must admint, that I don't understand your answer. If VT_BSTR is Unicode string, and I pass Unicode string as parameter, so it should be correct at the end, or not?
In Net Express v5.1 help navigate as follows from contents: Programming ---- Object-Oriented Programming ---- OO Class Libraries --- OO COBOL Class Library Reference ---- OLE Automation Class Library
putstring accepts PIC X(...) so is expecting sbcs and it converts to Unicode. Really need both sides to see where is could be going wrong. If its a byte array you want to pass rather than a string then a safearray of VT_UI1 would likely be better.
Ok, thanks for Help topic, I will try to get thru it. In my case on the other side, in C#, I put data to string[] array

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.