The following table lists the IDL types that are supported and the Java type that each IDL type maps to.
IDL type | Java type |
boolean | boolean |
char | char |
double | double |
int | int |
int64 | long |
float | float |
long | int |
short | short |
UCHAR | byte |
BSTR | java.lang.String class |
LPCOLESTR | java.lang.String class |
CURRENCY/CY | long (divide by 10,000 to get the original value as a fixed-point number) |
DATE | double |
SCODE/HRESULT | int (see the com.ms.com.ComException class) |
VARIANT | com.ms.com.Variant class |
IUnknown* | com.ms.com.IUnknown interface |
IDispatch* | java.lang.Object class |
SAFEARRAY (typename) | com.ms.com.SafeArray class |
Typename* | single-element array of typename on [out], error on [in] |
void | void |
For information on accessing the contents of a VARIANT structure, see the Variant class.
IUnknown is the interface from which all COM interfaces are derived. The Java versions of COM interfaces are derived from com.ms.com.IUnknown. Because IUnknown is simply a placeholder for COM interfaces, you never have to call any methods on com.ms.com.IUnknown. If your Java program calls a COM method that takes a parameter of type com.ms.com.IUnknown, you can pass any COM interface. If your Java program calls a COM method that has com.ms.com.IUnknown as its return type, you can cast the return value to the COM interface you're expecting.
Certain IDL attributes cause parameters to be treated in the following ways:
The following example passes an array object to a COM server and references its elements from the COM server. This may seem difficult because the elements don't have property names. Moreover, because it is an object reference, you cannot use subscript notation.
Assume you create an array object
var myarray = new Array(10);
and pass it to a COM server.
You can wrap each of your objects in a com.ms.com.Variant and put them into a com.ms.com.SafeArray, shown as follows:
hub.Hub_Dispatch mess = new hub.Hub(); Variant[] vars = new Variant[3]; vars[0]=new Variant(new Integer(99)); Vector datum = new Vector(); datum.addElement(new Date()); datum.addElement(new Vector()); vars[1]=new Variant(datum); vars[2]=new Variant(new StringBuffer("Howdy")); SafeArray safe = new SafeArray(Variant.VariantVariant,3); safe.setVariants(0,3,vars,0); Variant sender = new Variant(safe,false); mess.sendObjects(sender);
where Hub has a method with the following prototype:
public void sendObjects(Object[] data);