Variant<T extends Object?>
extension type
com
A Dart wrapper around the COM VARIANT structure.
VARIANT is a tagged union used extensively in COM and Automation APIs to
transport values whose type is determined at runtime.
This wrapper provides:
- Safe allocation and cleanup
- Dart-friendly accessors
- Type-checked reads via the generic parameter
T - Strongly-typed factory constructors for common VARIANT kinds
Memory for the underlying VARIANT is allocated natively. Any contained
resources (e.g., BSTR, interface pointers) are owned by the VARIANT.
Call free when the Variant is no longer needed to avoid leaks.
The generic parameter T represents the expected Dart view of the
stored value. It is not used to determine the underlying VARIANT type.
Instead, it is validated at read time.
A mismatch between the actual vt and T results in a StateError.
Constructors
- Variant()
-
Creates a new empty Variant.
factory
- Variant.from(T value)
-
Creates a new Variant initialized with the provided
value.factory -
Variant.fromPointer(Pointer<
VARIANT> ptr) -
Creates a Variant from an existing VARIANT pointer.
factory
Properties
- address → int
-
Access to the raw pointer value.
On 32-bit systems, the upper 32-bits of the result are 0.
no setterinherited
- boolVal ↔ bool
-
getter/setter pair
- bstrVal ↔ BSTR
-
getter/setter pair
- bVal ↔ int
-
getter/setter pair
-
byref
↔ Pointer<
NativeType> -
getter/setter pair
- cVal ↔ CHAR
-
getter/setter pair
- cyVal ↔ CY
-
getter/setter pair
- date ↔ double
-
getter/setter pair
- dblVal ↔ double
-
getter/setter pair
- decVal ↔ DECIMAL
-
getter/setter pair
- fltVal ↔ double
-
getter/setter pair
- hashCode → int
-
The hash code for a Pointer only depends on its address.
no setterinherited
- intVal ↔ int
-
getter/setter pair
- isEmpty → bool
-
Whether this VARIANT is empty (VT_EMPTY).
no setter
- isNull → bool
-
Whether this VARIANT represents a COM
null(VT_NULL).no setter - iVal ↔ int
-
getter/setter pair
- llVal ↔ int
-
getter/setter pair
- lVal ↔ int
-
getter/setter pair
-
parray
↔ Pointer<
SAFEARRAY> -
getter/setter pair
-
pboolVal
↔ Pointer<
Int16> -
getter/setter pair
-
pbstrVal
↔ Pointer<
Pointer< Utf16> > -
getter/setter pair
-
pbVal
↔ Pointer<
Uint8> -
getter/setter pair
- pcVal ↔ PSTR
-
getter/setter pair
-
pcyVal
↔ Pointer<
CY> -
getter/setter pair
-
pdate
↔ Pointer<
Double> -
getter/setter pair
-
pdblVal
↔ Pointer<
Double> -
getter/setter pair
-
pdecVal
↔ Pointer<
DECIMAL> -
getter/setter pair
- pdispVal ↔ IDispatch?
-
getter/setter pair
-
pfltVal
↔ Pointer<
Float> -
getter/setter pair
-
pintVal
↔ Pointer<
Int32> -
getter/setter pair
-
piVal
↔ Pointer<
Int16> -
getter/setter pair
-
pllVal
↔ Pointer<
Int64> -
getter/setter pair
-
plVal
↔ Pointer<
Int32> -
getter/setter pair
-
pparray
↔ Pointer<
Pointer< SAFEARRAY> > -
getter/setter pair
-
ppdispVal
↔ Pointer<
VTablePointer> -
getter/setter pair
-
ppunkVal
↔ Pointer<
VTablePointer> -
getter/setter pair
-
pscode
↔ Pointer<
Int32> -
getter/setter pair
-
puintVal
↔ Pointer<
Uint32> -
getter/setter pair
-
puiVal
↔ Pointer<
Uint16> -
getter/setter pair
-
pullVal
↔ Pointer<
Uint64> -
getter/setter pair
-
pulVal
↔ Pointer<
Uint32> -
getter/setter pair
- punkVal ↔ IUnknown?
-
getter/setter pair
-
pvarVal
↔ Pointer<
VARIANT> -
getter/setter pair
- ref ↔ VARIANT
-
Provides access to the underlying VARIANT structure.
getter/setter pair
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- scode ↔ int
-
getter/setter pair
- uintVal ↔ int
-
getter/setter pair
- uiVal ↔ int
-
getter/setter pair
- ullVal ↔ int
-
getter/setter pair
- ulVal ↔ int
-
getter/setter pair
- value ↔ T
-
Gets or sets the Dart value represented by this VARIANT.
getter/setter pair
- vt ↔ VARENUM
-
The
vtfield of the VARIANT, representing the type of data stored.getter/setter pair
Methods
-
cast<
U extends NativeType> () → Pointer< U> -
Reinterprets the address of this pointer as the address of a
U.inherited -
copy(
) → Variant< T> - Creates a deep copy of this Variant.
-
free(
) → void - Releases all resources held by this Variant and frees its memory.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
-
tryGet<
R extends Object?> () → R? -
Attempts to read the value stored in this VARIANT as type
R.
Operators
-
operator ==(
Object other) → bool -
Equality for Pointers only depends on their address.
inherited
Static Methods
-
bool$(
bool value) → VariantBool - Creates a Variant holding a VARIANT_BOOL value.
-
bstr(
String value) → VariantBSTR - Creates a Variant holding a BSTR value.
-
dispatch(
IDispatch value) → VariantDispatch - Creates a Variant holding an IDispatch value.
-
dispatchByRef(
Pointer< VTablePointer> value) → VariantDispatchByRef - Creates a Variant holding a reference to an IDispatch value.
-
double$(
double value) → VariantDouble - Creates a Variant holding a Double value.
-
float(
double value) → VariantFloat - Creates a Variant holding a Float value.
-
int16(
int value) → VariantInt16 - Creates a Variant holding an Int16 value.
-
int32(
int value) → VariantInt32 - Creates a Variant holding an Int32 value.
-
int64(
int value) → VariantInt64 - Creates a Variant holding an Int64 value.
-
int8(
int value) → VariantInt8 - Creates a Variant holding an Int8 value.
-
uint16(
int value) → VariantUint16 - Creates a Variant holding a Uint16 value.
-
uint32(
int value) → VariantUint32 - Creates a Variant holding a Uint32 value.
-
uint64(
int value) → VariantUint64 - Creates a Variant holding a Uint64 value.
-
uint8(
int value) → VariantUint8 - Creates a Variant holding a Uint8 value.
-
unknown(
IUnknown value) → VariantUnknown - Creates a Variant holding an IUnknown value.
-
unknownByRef(
Pointer< VTablePointer> value) → VariantUnknownByRef - Creates a Variant holding a reference to an IUnknown value.