Marshal.CreateWrapperOfType 方法

定义

重载

CreateWrapperOfType(Object, Type)
已过时.

在指定类型的对象中包装指定的 COM 对象。

CreateWrapperOfType<T,TWrapper>(T)

在指定类型的对象中包装指定的 COM 对象。

CreateWrapperOfType(Object, Type)

Source:
Marshal.NoCom.cs
Source:
Marshal.NoCom.cs
Source:
Marshal.NoCom.cs

注意

CreateWrapperOfType(Object, Type) may be unavailable in future releases. Instead, use CreateWrapperOfType<T,T2>(T). For more info, go to http://go.microsoft.com/fwlink/?LinkID=296519

在指定类型的对象中包装指定的 COM 对象。

public:
 static System::Object ^ CreateWrapperOfType(System::Object ^ o, Type ^ t);
[System.Obsolete("CreateWrapperOfType(Object, Type) may be unavailable in future releases. Instead, use CreateWrapperOfType<T,T2>(T). For more info, go to http://go.microsoft.com/fwlink/?LinkID=296519")]
[System.Security.SecurityCritical]
public static object CreateWrapperOfType (object o, Type t);
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
public static object? CreateWrapperOfType (object? o, Type t);
[System.Security.SecurityCritical]
public static object CreateWrapperOfType (object o, Type t);
public static object CreateWrapperOfType (object o, Type t);
public static object? CreateWrapperOfType (object? o, Type t);
[<System.Obsolete("CreateWrapperOfType(Object, Type) may be unavailable in future releases. Instead, use CreateWrapperOfType<T,T2>(T). For more info, go to http://go.microsoft.com/fwlink/?LinkID=296519")>]
[<System.Security.SecurityCritical>]
static member CreateWrapperOfType : obj * Type -> obj
[<System.Runtime.Versioning.SupportedOSPlatform("windows")>]
static member CreateWrapperOfType : obj * Type -> obj
[<System.Security.SecurityCritical>]
static member CreateWrapperOfType : obj * Type -> obj
static member CreateWrapperOfType : obj * Type -> obj
Public Shared Function CreateWrapperOfType (o As Object, t As Type) As Object

参数

o
Object

要包装的对象。

t
Type

要创建的包装器的类型。

返回

新包装的对象,该对象是所需类型的实例。

属性

例外

t 必须派生自 __ComObject

- 或 -

t是Windows 运行时类型。

t 参数为 null

o 不支持所有必需的接口,因此无法转换为目标类型。

注解

CreateWrapperOfType 将一个 COM 类类型(通常是基 __ComObject 类型)转换为另一个 COM 类类型。 输入 COM 对象(由参数 o表示)是运行时 可调用包装器, (RCW)

to 参数必须是其签名使用 System.Runtime.InteropServices.ComImportAttribute进行特性化的类。 Tlbimp.exe (类型库导入程序) 工具在导入类型库时为你应用此属性。 如果在源代码中手动创建 RCW,则应将此属性应用于表示原始 coclass 以表示其 COM 源的托管签名。

Tlbimp.exe 将 COM coclass 导入为托管类和接口。 coclass 接口与原始 coclass 具有相同的名称,托管类的原始 coclass 名称追加了“Class”。 例如,名为 的 MyCoclass coclass 将成为名为 的 MyCoclass coclass 接口和名为 的 MyCoclassClass托管类。 由于 t 必须是类,而不是接口,因此请确保指定托管类 (MyCoclassClass) 而不是 coclass 接口。

注意

由于新的 RCW 实例包装由原始 RCW 公开的 IUnknown 指针,因此将丢失输入 COM 对象的标识。

另请参阅

适用于

CreateWrapperOfType<T,TWrapper>(T)

Source:
Marshal.NoCom.cs
Source:
Marshal.NoCom.cs
Source:
Marshal.NoCom.cs

在指定类型的对象中包装指定的 COM 对象。

public:
generic <typename T, typename TWrapper>
 static TWrapper CreateWrapperOfType(T o);
[System.Security.SecurityCritical]
public static TWrapper CreateWrapperOfType<T,TWrapper> (T o);
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
public static TWrapper CreateWrapperOfType<T,TWrapper> (T? o);
public static TWrapper CreateWrapperOfType<T,TWrapper> (T o);
[<System.Security.SecurityCritical>]
static member CreateWrapperOfType : 'T -> 'Wrapper
[<System.Runtime.Versioning.SupportedOSPlatform("windows")>]
static member CreateWrapperOfType : 'T -> 'Wrapper
static member CreateWrapperOfType : 'T -> 'Wrapper
Public Shared Function CreateWrapperOfType(Of T, TWrapper) (o As T) As TWrapper

类型参数

T

要包装的对象的类型。

TWrapper

要返回的对象的类型。

参数

o
T

要包装的对象。

返回

TWrapper

新包装的对象。

属性

例外

T 必须派生自 __ComObject

- 或 -

T是Windows 运行时类型。

o 无法转换为 TWrapper,因为它不支持所有需要的接口。

注解

CreateWrapperOfType<T,TWrapper>(T) 将 类型的 T COM 对象转换为 TWrapper COM 类类型。 输入 COM 对象(由参数 o表示)是运行时 可调用包装器, (RCW)

T泛型类型参数和 o 参数都必须是其签名使用 System.Runtime.InteropServices.ComImportAttribute 特性进行特性化的类。 Tlbimp.exe (类型库导入程序) 工具在导入类型库时为你应用此属性。 如果在源代码中手动创建 RCW,则应将此属性应用于表示原始 coclass 以表示其 COM 源的托管签名。

Tlbimp.exe 将 COM coclass 导入为托管类和接口。 coclass 接口与原始 coclass 具有相同的名称,托管类的原始 coclass 名称追加了“Class”。 例如,名为 的 MyCoclass coclass 将成为名为 的 MyCoclass coclass 接口和名为 的 MyCoclassClass托管类。 由于T 必须是类,而不是接口,因此请确保指定托管类 (MyCoclassClass) 而不是 coclass 接口。

注意

将丢失输入 COM 对象的标识,因为新的 RCW 实例包装由原始 RCW 公开的 IUnknown 指针。

适用于