Highlighted
Absent Member.
Absent Member.
1448 views

[archive] Passing Byte Array to COM routine

[Migrated content. Thread originally posted on 07 April 2006]

I need to pass a group item containing mixed COMP-6 and DISPLAY data to an ActiveX control. When passing it as a simple string, it gets truncated at the first null. Also, some characters get translated. I can modify the ActiveX control to take a byte array, but I can't get COBOL (Version 5.2) to create that data type.

Any suggestions for how to resolve this?

Thanks.

Glenn
0 Likes
5 Replies
Highlighted
Absent Member.
Absent Member.

RE: [archive] Passing Byte Array to COM routine

Need to know more about the recepient. Can you post the definition file and documentation of the property/method.

Is this something you are developing yourself?

Note that COM use VARIANT for intraprocess communication and VARIANT is not designed to handle complex data structures, but basic ones.

If you are designing the ActiveX yourself, it might be an idea to tell what you are passing and why you want to maintain COBOL specific datatypes like COMP-6.
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] Passing Byte Array to COM routine

In general, we've had problems using COMP-n data with ActiveX controls. Typically we've seen behavior like you are talking about. So, we just avoid using the COMP-n data by converting it to non-COMP before sending to ActiveX control and then doing the reverse after we inquire the ActiveX control.

Rob
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] Passing Byte Array to COM routine

The difficulty here is that we're retrofitting existing functionality. The current COBOL code calls a Windows DLL and passes it a complex data structure. The complex data structure's internal structure changes depending on part of that structure. So, I'm calling a dll routine (say "abc") and passing it the complex data structure. "abc" determines from the content of the initial part of the data structure how to interpret the remaining part of the structure (e.g. COMP-6, DISPLAY, mixed). That all works fine.

Now we want to perform that call across a web services link which requires that the data be marshalled as a COM object. In native COM, I'd just pass a byte array and let Web Services Base64 encode it for me. It appears that I can't do that with AcuCOBOL 5.2.

I have a workaround at this point in that I Base64 encode the array before passing it to Web Services as a string. It's more complex than I'd like to take that approach and I was hoping that perhaps I had overlooked some more obvious solution.

(I am not in the office as I write this and can't post the relevant sections of the .def file, but I do know they show up as SAFEARRAY if I'm expecting a byte array).

Glenn
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] Passing Byte Array to COM routine

I should also add that for several of the functions in this DLL I was able to take the approach of breaking down the complex structure into its component parts. The gotcha is the "abc" routine is designed as sort of a flexible RPC interface and I cannot predict what data types will need to be passed through it; I just need to be able to handle it as a byte-array or some other equivalent that will just pass the storage contents regardless of format just as I'm doing today with the direct call of the dll.

Glenn
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] Passing Byte Array to COM routine

The problem here is that what you want to pass can be best categorized as the variant datatype VT_USERDEFINED or VT_BLOB for instance, neither of which is implemented by ACUCOBOL-GT.

What happens is that the runtime will end up trying to pass the binary stream as a VT_BSTR, but VT_BSTR has the potential problem that its conversion routines watch out for terminating ascii 0, e.g. LOW-VALUE.

Now, having said this, we did have some issues on the conversion which has been addressed in the upcoming version. I don't know however, if this will help on your situation and I do know that if it does, it is sheer luck and not by design of the VARIANT datatype.

Sorry, this is really a special case. I am afraid you will have to break the structure up in individual parts. Or, you can always request a enhancement to, say implement support for VT_BLOB, VT_USERDEFINED etc.
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.