Marshal.GetComInterfaceForObject 方法

定义

返回一个接口指针,该指针表示对象的接口。

重载

名称 说明
GetComInterfaceForObject(Object, Type)
已过时.

返回指向 IUnknown 接口的指针,该接口表示指定对象上的指定接口。 默认启用自定义查询接口访问。

GetComInterfaceForObject(Object, Type, CustomQueryInterfaceMode)
已过时.

返回指向 IUnknown 接口的指针,该接口表示指定对象上的指定接口。 自定义查询接口访问由指定的自定义模式控制。

GetComInterfaceForObject<T,TInterface>(T)

返回指向 IUnknown 接口的指针,该接口代表指定类型的对象上的指定接口。 默认启用自定义查询接口访问。

GetComInterfaceForObject(Object, Type)

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

注意

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

返回指向 IUnknown 接口的指针,该接口表示指定对象上的指定接口。 默认启用自定义查询接口访问。

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

参数

o
Object

提供接口的对象。

T
Type

请求的接口的类型。

返回

IntPtr

nativeint

表示对象的指定接口的接口指针。

属性

例外

参数 T 不是接口。

-或-

该类型对 COM 不可见。

-或-

参数 T 是泛型类型定义。

o 参数不支持请求的接口。

参数 onull.

-或-

参数 Tnull.

注解

此方法返回一个接口指针,该指针表示指定对象上请求的接口。 如果你有一个需要传递接口指针的非托管方法,则它特别有用。 使用此方法调用对象会导致引用计数在返回指针之前在接口指针上递增。 完成指针后,始终用于 Marshal.Release 递减引用计数。 在使用原始 COM 接口指针时,必须遵循 COM 定义的规则。

GetComInterfaceForObject(Object, Type) 调用公开 COM 对象参数作为 IntPtr 类型或自定义封送的方法时非常有用。 虽然不太常见,但可以在托管对象上使用此方法来获取指向对象的 COM 可调用包装器的指针。 例如,可以对导出到 COM 的托管对象使用 GetComInterfaceForObject(Object, Type) ,以获取接口 System.Runtime.InteropServices.UCOMIConnectionPointContainer指针。 无法获取指向类接口的指针,因为类接口缺少传递给第二个参数的相应类型(t)。 而是用于 Marshal.GetIDispatchForObject 调用 COM 可调用包装器的默认接口(通常是自动调度类接口)上的成员。

默认情况下,方法 GetComInterfaceForObject(Object, Type) 重载允许查询接口自定义。 若要指定是否应用查询接口自定义,请使用 GetComInterfaceForObject(Object, Type, CustomQueryInterfaceMode) 方法重载。

有关详细信息,请参阅 COM 可调用包装器运行时可调用包装器 文章。

另请参阅

适用于

GetComInterfaceForObject(Object, Type, CustomQueryInterfaceMode)

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

注意

GetComInterfaceForObject(Object, Type, CustomQueryInterfaceMode) and support for ICustomQueryInterface may be unavailable in future releases.

返回指向 IUnknown 接口的指针,该接口表示指定对象上的指定接口。 自定义查询接口访问由指定的自定义模式控制。

public:
 static IntPtr GetComInterfaceForObject(System::Object ^ o, Type ^ T, System::Runtime::InteropServices::CustomQueryInterfaceMode mode);
[System.Obsolete("GetComInterfaceForObject(Object, Type, CustomQueryInterfaceMode) and support for ICustomQueryInterface may be unavailable in future releases.")]
[System.Security.SecurityCritical]
public static IntPtr GetComInterfaceForObject(object o, Type T, System.Runtime.InteropServices.CustomQueryInterfaceMode mode);
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
public static IntPtr GetComInterfaceForObject(object o, Type T, System.Runtime.InteropServices.CustomQueryInterfaceMode mode);
[System.Security.SecurityCritical]
public static IntPtr GetComInterfaceForObject(object o, Type T, System.Runtime.InteropServices.CustomQueryInterfaceMode mode);
public static IntPtr GetComInterfaceForObject(object o, Type T, System.Runtime.InteropServices.CustomQueryInterfaceMode mode);
[<System.Obsolete("GetComInterfaceForObject(Object, Type, CustomQueryInterfaceMode) and support for ICustomQueryInterface may be unavailable in future releases.")>]
[<System.Security.SecurityCritical>]
static member GetComInterfaceForObject : obj * Type * System.Runtime.InteropServices.CustomQueryInterfaceMode -> nativeint
[<System.Runtime.Versioning.SupportedOSPlatform("windows")>]
static member GetComInterfaceForObject : obj * Type * System.Runtime.InteropServices.CustomQueryInterfaceMode -> nativeint
[<System.Security.SecurityCritical>]
static member GetComInterfaceForObject : obj * Type * System.Runtime.InteropServices.CustomQueryInterfaceMode -> nativeint
static member GetComInterfaceForObject : obj * Type * System.Runtime.InteropServices.CustomQueryInterfaceMode -> nativeint
Public Shared Function GetComInterfaceForObject (o As Object, T As Type, mode As CustomQueryInterfaceMode) As IntPtr

参数

o
Object

提供接口的对象。

T
Type

请求的接口的类型。

mode
CustomQueryInterfaceMode

枚举值之一 IUnknown::QueryInterface ,指示是否应用由一个 ICustomQueryInterface提供的自定义项。

返回

IntPtr

nativeint

表示对象的接口指针。

属性

例外

参数 T 不是接口。

-或-

该类型对 COM 不可见。

-或-

参数 T 是泛型类型定义。

对象 o 不支持请求的接口。

参数 onull.

-或-

参数 Tnull.

注解

GetComInterfaceForObject(Object, Type, CustomQueryInterfaceMode) 允许指定是否应用查询接口自定义。 默认情况下, GetComInterfaceForObject(Object, Type) 使用重载应用查询接口自定义。

适用于

GetComInterfaceForObject<T,TInterface>(T)

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

返回指向 IUnknown 接口的指针,该接口代表指定类型的对象上的指定接口。 默认启用自定义查询接口访问。

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

类型参数

T

o 的类型。

TInterface

要返回的接口的类型。

参数

o
T

提供接口的对象。

返回

IntPtr

nativeint

表示接口的 TInterface 接口指针。

属性

例外

参数 TInterface 不是接口。

-或-

该类型对 COM 不可见。

-或-

参数 T 是一种打开的泛型类型。

o 参数不支持 TInterface 接口。

参数 onull.

注解

此方法返回一个接口指针,该指针表示 TInterface 指定对象的接口。 如果你有一个需要传递接口指针的非托管方法,则它特别有用。 使用此方法调用对象会导致引用计数在返回指针之前在接口指针上递增。 使用完指针后,始终使用 Marshal.Release 该方法递减引用计数。 在使用原始 COM 接口指针时,必须遵循 COM 定义的规则。

GetComInterfaceForObject<T,TInterface>(T) 调用公开 COM 对象参数作为 IntPtr 类型或自定义封送的方法时非常有用。 还可以在托管对象上使用此方法来获取指向对象的 COM 可调用包装器的指针,尽管这不太常见。 例如,可以对导出到 COM 的托管对象使用 GetComInterfaceForObject<T,TInterface>(T) ,以获取接口 System.Runtime.InteropServices.UCOMIConnectionPointContainer指针。

默认情况下,方法 GetComInterfaceForObject<T,TInterface>(T) 重载允许查询接口自定义。 若要指定是否应用查询接口自定义,请使用 GetComInterfaceForObject(Object, Type, CustomQueryInterfaceMode) 方法重载。

有关详细信息,请参阅 COM 可调用包装器运行时可调用包装器 文章。

适用于