Export (0) Print
Expand All

VariantWrapper Class

Marshals data of type VT_VARIANT | VT_BYREF from managed to unmanaged code. This class cannot be inherited.

Namespace: System.Runtime.InteropServices
Assembly: mscorlib (in mscorlib.dll)

[SerializableAttribute] 
public ref class VariantWrapper sealed
/** @attribute SerializableAttribute() */ 
public final class VariantWrapper
SerializableAttribute 
public final class VariantWrapper
Not applicable.

The purpose of VariantWrapper is to add one level of indirection when marshaling a managed type to the corresponding VARIANT type.

You can use this class to wrap an Object that the interop marshaler passes as VT_VARIANT | VT_BYREF. In versions 1.0 and 1.1 of the .NET Framework, it was not possible to marshal variant data of type VT_VARIANT | VT_BYREF to unmanaged code. The interop marshaler passed a variant of the managed type (for example, VT_BSTR | VT_BYREF for String, or VT_I4 | VT_BYREF for Int32), but not VT_VARIANT | VT_BYREF.

One advantage of using VT_VARIANT | VT_BYREF variant types is that the type of data can be changed during a method call. For example, you can pass a VT_VARIANT| VT_BYREF variant type that contains a VT_BSTR and get a variant returned that contains a VT_I4 after a method call. Because the COM interop marshaler has no way of knowing when to pass VT_BSTR | VT_BYREF and when to pass VT_VARIANT | VT_BYREF, which points to a variant that contains a BSTR for parameters declared as VARIANT *, you can instruct the marshaler by using VariantWrapper.

Note that early binding is not supported; you can use VariantWrapper only when calling InvokeMember or with a Dispatch-only interface called in an early bound fashion. In C#, you must also use the ref keyword to specify ByRef semantics for any parameter of type VariantWrapper. In Visual Basic, ByRef semantics are added automatically for every implicit late binding call. Also note that nesting VariantWrapper objects and arrays of VariantWrapper objects is not supported.

The following code example demonstrates how to use the VariantWrapper class to wrap an Object that the interop marshaler passes as VT_VARIANT | VT_BYREF.

No code example is currently available or this language may not be supported.

System.Object
  System.Runtime.InteropServices.VariantWrapper

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0

Community Additions

ADD
Show:
© 2014 Microsoft