Difference between revisions of "Documentation/DevGuide/ProUNO/Bridge/Type Mappings"

From Apache OpenOffice Wiki
Jump to: navigation, search
m (FINAL VERSION FOR L10N)
m
Line 18: Line 18:
  
 
A method call to an Automation object is performed through <code>IDispatch::Invoke</code>. Invoke takes an argument of type <code>DISPPARAMS</code>, which contains the actual arguments for the method in an array of <code>VARIANTARG</code>. These <code>VARIANTARG</code>s are to be regarded as holders for the actual types. In most Automation languages you are not even aware of <code>IDispatch</code>. For example:
 
A method call to an Automation object is performed through <code>IDispatch::Invoke</code>. Invoke takes an argument of type <code>DISPPARAMS</code>, which contains the actual arguments for the method in an array of <code>VARIANTARG</code>. These <code>VARIANTARG</code>s are to be regarded as holders for the actual types. In most Automation languages you are not even aware of <code>IDispatch</code>. For example:
 
+
<source lang="idl">
 
   //UNO IDL
 
   //UNO IDL
 
   string func([in] long value);
 
   string func([in] long value);
   //VB  
+
</source>
 +
<source lang="vb">
 +
   ' VB  
 
   Dim value As Long
 
   Dim value As Long
 
   value= 100
 
   value= 100
 
   Dim ret As String
 
   Dim ret As String
 
   ret= obj.func( value)
 
   ret= obj.func( value)
 +
</source>
  
 
In this example, the argument is a long and the return value is a string. That is, <code>IDispatch::Invoke</code> would receive a <code>VARIANTARG</code> that contains a long and returns a <code>VARIANT</code> that contains a string.
 
In this example, the argument is a long and the return value is a string. That is, <code>IDispatch::Invoke</code> would receive a <code>VARIANTARG</code> that contains a long and returns a <code>VARIANT</code> that contains a string.

Revision as of 12:37, 22 October 2009



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