VariantWrapper 类

定义

注意

VariantWrapper and support for marshalling to the VARIANT type may be unavailable in future releases.

VT_VARIANT | VT_BYREF 类型的数据从托管代码封送到非托管代码。 此类不能被继承。

public ref class VariantWrapper sealed
[System.Obsolete("VariantWrapper and support for marshalling to the VARIANT type may be unavailable in future releases.")]
public sealed class VariantWrapper
public sealed class VariantWrapper
[System.Serializable]
public sealed class VariantWrapper
[<System.Obsolete("VariantWrapper and support for marshalling to the VARIANT type may be unavailable in future releases.")>]
type VariantWrapper = class
type VariantWrapper = class
[<System.Serializable>]
type VariantWrapper = class
Public NotInheritable Class VariantWrapper
继承
VariantWrapper
属性

示例

下面的代码示例演示如何使用VariantWrapper类来包装Object互操作封送器传递的封送器。VT_VARIANT | VT_BYREF

// Create an instance of an unmanged COM object.
UnmanagedComClass UnmanagedComClassInstance = new UnmanagedComClass();

// Create a string to pass to the COM object.
string helloString = "Hello World!";

// Wrap the string with the VariantWrapper class.
object var = new System.Runtime.InteropServices.VariantWrapper(helloString);

// Pass the wrapped object.
UnmanagedComClassInstance.MethodWithStringRefParam(ref var);
' Create an instance of an unmanged COM object.
Dim UnmanagedComClassInstance As New UnmanagedComClass()

' Create a string to pass to the COM object.
Dim helloString As String = "Hello World!"

' Wrap the string with the VariantWrapper class.
Dim var As Object = New System.Runtime.InteropServices.VariantWrapper(helloString)

' Pass the wrapped object.
UnmanagedComClassInstance.MethodWithStringRefParam(var)

注解

VariantWrapper目的是将托管类型封送给相应VARIANT类型时添加一个间接级别。

可以使用此类来包装 Object 互操作封送器传递的 VT_VARIANT | VT_BYREF封送器。 在.NET Framework版本 1.0 和 1.1 中,无法将类型类型的VT_VARIANT | VT_BYREF变体数据封送给非托管代码。 互操作封送器传递了托管类型的变体 (,例如, VT_BSTR | VT_BYREF Int32 StringVT_I4 | VT_BYREF或) ,但不是。VT_VARIANT | VT_BYREF

使用 VT_VARIANT | VT_BYREF 变体类型的一个优点是,方法调用期间可以更改数据类型。 例如,可以传递包含一VT_BSTRVT_VARIANT | VT_BYREF变量类型,并获取返回的变量,该变体包含VT_I4方法调用后返回的变体。 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.

请注意,不支持早期绑定;只能在调用InvokeMember或早期绑定方式调用仅调度接口时使用VariantWrapper。 在 C# 中,还必须使用ref关键字为类型VariantWrapper的任何参数指定ByRef语义。 在Visual Basic中,ByRef为每个隐式后期绑定调用自动添加语义。 另请注意,不支持嵌套 VariantWrapper 对象和对象数组 VariantWrapper

构造函数

VariantWrapper(Object)

使用指定的 Object 参数初始化 VariantWrapper 类的新实例。

属性

WrappedObject

获取由 VariantWrapper 对象包装的对象。

方法

Equals(Object)

确定指定对象是否等于当前对象。

(继承自 Object)
GetHashCode()

作为默认哈希函数。

(继承自 Object)
GetType()

获取当前实例的 Type

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
ToString()

返回表示当前对象的字符串。

(继承自 Object)

适用于