Type Mappings

From Apache OpenOffice Wiki
Jump to: navigation, search



When a UNO object is called from an Automation environment, such as VB, then depending on the signature of the called method, values of Automation types are converted to values of UNO types. If values are returned, either as out-arguments or return value, then values of UNO types are converted to values of Automation types. The results of these conversions are governed by the values to be converted and the respective type mapping.

The type mapping describes how a type from the Automation environment is represented in the UNO environment and vice versa. Automation types and UNO types are defined in the respective IDL languages, MIDL and UNO IDL. Therefore, the type mapping will refer to the IDL types.

The IDL types have a certain representation in a particular language. This mapping from IDL types to language specific types must be known in order to use the Automation bridge properly. Languages for which a UNO language binding exists will find the mapping in the language binding documentation. Automation capable languages can provide information about how Automation types are to be used (for example, Visual Basic, Delphi).

Some Automation languages may not provide a complete mapping for all Automation types. For example, JScript cannot provide float values. If you use C or C++, then all Automation types can be used directly.

A method call to an Automation object is performed through IDispatch::Invoke. Invoke takes an argument of type DISPPARAMS, which contains the actual arguments for the method in an array of VARIANTARG. These VARIANTARGs are to be regarded as holders for the actual types. In most Automation languages you are not even aware of IDispatch. For example:

  //UNO IDL
  string func([in] long value);
  ' VB 
  Dim value As Long
  value= 100
  Dim ret As String
  ret= obj.func( value)

In this example, the argument is a long and the return value is a string. That is, IDispatch::Invoke would receive a VARIANTARG that contains a long and returns a VARIANT that contains a string.

When an Automation object is called from UNO through com.sun.star.script.XInvocation:invoke, then all arguments are provided as anys. The any, similiar to the VARIANTARG, acts as a holder for the actual type. To call Automation objects from UNO you will probably use StarBasic. Then the XInvocation interface is hidden, as in IDispatch in Visual Basic.

The bridge converts values according to the type mapping specified at Default Mappings. Moreover, it tries to coerce a conversion if a value does not have a type that conforms with the default mapping (Conversion Mappings).

In some situations, it may be necessary for an Automation client to tell the bridge what the argument is supposed to be. For this purpose you can use the Value Object (Value Objects).

Content on this page is licensed under the Public Documentation License (PDL).
Personal tools
In other languages