Using COBOL Data Types as ActiveX and COM Object Parameters

When programming with ActiveX controls and COM objects, you can MODIFY property values using COBOL data items, literals, and figurative constants. You can also pass them as parameters to methods using MODIFY.

When passing parameters to an ActiveX control or COM object method, the ACUCOBOL-GT runtime converts the COBOL parameters into variant parameters. Variant parameters have a data type associated with them. More than 40 different variant types exist. Each type name starts with "VT_". For example, VT_I4 is a 4-byte signed integer. VT_R8 is an 8-byte real (floating point) number. VT_BSTR is a string. The rules applied by the runtime to determine the variant type are given at the end of this section.

A method or property can act differently depending on the type of data passed to it in a variant. For example, a type of variant parameter called VT_UNKNOWN is commonly used to represent COM objects. A property or method might expect either VT_I4 or VT_UNKNOWN (that is, IUnknown pointer) and will act differently depending on which one it receives. If the runtime converts a COM object handle to a VT_I4 instead of a VT_UNKNOWN, the property or method being called might not act as expected. The runtime determines which of the two variant types to pass based on the USAGE parameters of the COBOL data item.

Some ActiveX and COM methods and properties take VT_VARIANT parameters, a generic variant type. This usually means that these methods accept more than one type of variant parameter. For example, you could pass a VT_I4, VT_R8, or a VT_BSTR as a VT_VARIANT parameter. The ActiveX or COM property or method could convert the passed parameter into a specific variant type. It could also act differently depending on the type of variant that was passed. For example, suppose an ActiveX or COM object had a table where rows could be referred to by a character string name or by their numeric index. A method that returns a row in the table could take either the name or index of the row as a parameter. The method could assume that if the parameter is a VT_BSTR, it is a row name; and if the parameter is a VT_I4, it is a numeric index.

If the ActiveX control or COM object property or method parameter is one of the standard variant types, ACUCOBOL-GT attempts to convert the COBOL data to the expected type. For example, if an ActiveX control property is type VT_I4 (i.e., 4-byte integer), and the COBOL data type is PIC X(10), ACUCOBOL-GT tries to convert the value of the PIC X(10) item into a number and pass it as a VT_I4 type variant.

If the property or method parameter type is VT_VARIANT, then ACUCOBOL-GT converts the COBOL data item into a specific variant type parameter using the following rules:

  1. The PICTURE and USAGE clauses determine the type.
  2. If the data item is alphabetic, alphanumeric, or alphanumeric edited, it is passed as a VT_BSTR.
  3. If the data item is USAGE HANDLE or POINTER, and the property or method parameter type is VT_VARIANT, it is passed as a VT_UNKNOWN. If the data item is another binary (USAGE COMP-..., BINARY, HANDLE, POINTER, etc.), it is passed as a VT_I4.
  4. If the data item is USAGE FLOAT or DOUBLE, it is passed as a VT_R8.
  5. If the data item is another numeric type, it is passed as a VT_I4.

Note that the compiler generates an error message if a figurative constant is passed as a parameter where the method or property expects a " by reference" parameter. That error message is, " Illegal parameter: literal". This is the same error message you get when passing a figurative constant as a USING parameter in a CALL statement. One way to tell that the ActiveX/COM method expects a "by reference" parameter is by viewing the entry in the COPY file for that control or object. If the type has "BYREF" or if the numeric value divided by 16384 is odd, then you may not pass a figurative constant.