Mapping of Simple Types

From Apache OpenOffice Wiki
< Documentation‎ | DevGuide
Revision as of 12:40, 22 October 2009 by BMarcelly (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search



Many languages have equivalents for the IDL simple types, such as integer and floating point types. Some languages, however, may not support all these types. For example, JScript is a typeless language and only recognizes a general number type. Internally, it uses four byte signed integer values and double values to represent a number. When a UNO method is called that takes a float as an argument, and that value is at some point returned to the caller, then the values may differ slightly. This is because the bridge converts the double to a float, which is eventually converted back to a double.

If a UNO method takes an any as argument and the implementation expects a certain type within the any, then the bridge is not always able to provide the expected value. Assuming, that a UNO method takes an any that is supposed to contain a short and the method is to be called from JScript, then the bridge will provide an any containing a four byte integer. This may result in an exception from the initiator of the call The solution is to use a Value Object (Value Objects).

Unlike Automation, there are unsigned integer types in UNO. To provide a positive value that exceeds the maximum value of the corresponding signed type, you have to use the corresponding negative value. For example, to call the following UNO function in VB with the value 32768 (0x8000) you need to pass -32768 .

  //UNO IDL
  void foo(unsigned short value);
  ' VB
  Dim val As Integer 'two byte signed integer
  val = -32768
  obj.foo(val)

The rule for calculating the negative equivalent is:

 signed_value = unsigned_value - (max_unsigned +1)

In the preceding example, unsigned_value is the value that we want to pass, and which is 32768. This value is one too many for the VB type Integer, that is why we have to provide a negative value. max_unsigned has the value 65535 for a two byte integer. So the equation is

 -32768 = 32768 - (65535 + 1)

Alternatively you can use a type with a greater value range. The Automation bridge will then perform a narrowing conversion.

  Dim val As Long 'four byte signed integer
  val = 32768
  obj.foo(val)'expects a two byte unsigned int

For more information about conversions see chapter Conversion Mappings.

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