通过


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
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 运行时类型。

参数 tnull.

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

注解

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

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

Tlbimp.exe 将 COM coclass 导入为托管类和接口。 coclass 接口的名称与原始 coclass 相同,托管类具有追加有“Class”的原始 coclass 名称。 例如,调用 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
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 相同,托管类具有追加有“Class”的原始 coclass 名称。 例如,调用 MyCoclass 的 coclass 将成为调用 MyCoclass 的 coclass 接口和一个名为 MyCoclassClass托管类的托管类。 由于T 必须是类,而不是接口,因此请务必指定托管类(MyCoclassClass)而不是 coclass 接口。

注释

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

适用于