Microsoft SDK for Java

SafeArray Class Constructors

The SafeArray Class contains the following constructors:

SafeArray(int vt)
SafeArray(int vt, int celems)
SafeArray(int vt, int celems1, int celems2)
SafeArray(int vt, int lbounds[], int celems[])
SafeArray(String s)
getPhysicalSafeArray()

SafeArray(int vt)

Creates a SafeArray instance that wraps the NULL pointer. The main purpose of this constructor is to pass NULL to Component Object Model (COM) methods that accept SAFEARRAYs.

Syntax

public SafeArray(int vt);

The variant type of the element must be one of the Variant.VariantXXX constants. Neither the VariantByref nor the VariantArray modifier should be set in the element variant type; setting either of these modifiers will cause a run-time error to occur.

Parameters

vt The variant type of the element.

SafeArray(int vt, int celems)

Creates a one-dimensional SafeArray object. Valid indexes range from zero (inclusive) to celems (exclusive). Note that this convention follows the C language practice of indicating the number of elements rather than the Microsoft® Visual Basic® convention of indicating the upper bound.

The variant type of the element must be one of the Variant.VariantXXX constants. Neither the VariantArray nor the VariantByref modifier can be set.

Syntax

public SafeArray(int vt, int celems);

Parameters

vt The variant type of the element.
celems The number of elements.

SafeArray(int vt, int celems1, int celems2)

Creates a two-dimensional SafeArray object.

Syntax

public SafeArray(int vt, int celems1, int celems2);

The constructor follows the C language practice of indicating the number of elements rather than the Microsoft® Visual Basic® convention of indicating the upper bound.

The expression:

new SafeArray(Variant.VariantVariant, 21, 11);

is equivalent to the Visual Basic declaration:

Example

Option Base 0
Dim A(20, 10)

The variant type of the element must be one of the Variant.VariantXXX constants. Neither the VariantByref nor the VariantArray modifier should be set in the element variant type; setting either of these modifiers will cause a run-time error to occur.

Parameters

vt The variant type of the element.
celems1 The number of elements in the first dimension.
celems2 The number of elements in the second dimension.

SafeArray(int vt, int lbounds[], int celems[])

Creates a SafeArray object of arbitrary shape.

Syntax

public SafeArray(int vt, int lbounds[], int celems[]);

The lbounds array indicates the lower bound of each dimension. The celems array (which must have the same length as lbounds) gives the number of elements that are in each dimension. If lbounds is null, all the lower bound values default to zero. The variant type of the element must be one of the Variant.VariantXXX constants. Neither the VariantArray nor VariantByref modifier can be set.

The following Java code creates a 3-dimensional SafeArray:

Example

int lbounds[] = {-1,-3, -4};
int celems[] = {10, 20, 30};
SafeArray A = new SafeArray(Variant.VariantVariant, lbounds,
celems);

This Visual Basic declaration creates an array with the same shape as the SafeArray created above:

Dim A(-1 To 8, -3 To 16, -4 To 25)

Parameters

vt The variant type of the element.
lbounds The lower bounds of each dimension.
celems The number of elements in each dimension.

SafeArray(String s)

Creates a VT_UI1 SafeArray object from a string.

Syntax

public SafeArray(String s);

Each character of the string occupies two elements of the array to form a single Unicode character. The array is not null terminated. This constructor corresponds to the standard Automation conversion from VT_BSTR to VT_ARRAY|VT_UI1.

Parameters

s The string used to initialize the new SafeArray object.

getPhysicalSafeArray()

Retrieves the linear address of the actual SAFEARRAY data structure, which is packaged as a Java integer. This method is provided only to aid in debugging. Other than displaying information, there are no useful operations that can be performed with this value from Java.

Syntax

public native int getPhysicalSafeArray();

Return Value

Returns the linear address of the represented SAFEARRAY.

© 1999 Microsoft Corporation. All rights reserved. Terms of use.