通过


Marshal.QueryInterface(IntPtr, Guid, IntPtr) 方法

定义

从 COM 对象请求指向指定接口的指针。

public:
 static int QueryInterface(IntPtr pUnk, Guid % iid, [Runtime::InteropServices::Out] IntPtr % ppv);
[System.Security.SecurityCritical]
public static int QueryInterface(IntPtr pUnk, ref Guid iid, out IntPtr ppv);
public static int QueryInterface(IntPtr pUnk, in Guid iid, out IntPtr ppv);
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
public static int QueryInterface(IntPtr pUnk, ref Guid iid, out IntPtr ppv);
public static int QueryInterface(IntPtr pUnk, ref Guid iid, out IntPtr ppv);
public static int QueryInterface(IntPtr pUnk, ref readonly Guid iid, out IntPtr ppv);
[<System.Security.SecurityCritical>]
static member QueryInterface : nativeint * Guid * nativeint -> int
static member QueryInterface : nativeint * Guid * nativeint -> int
[<System.Runtime.Versioning.SupportedOSPlatform("windows")>]
static member QueryInterface : nativeint * Guid * nativeint -> int
Public Shared Function QueryInterface (pUnk As IntPtr, ByRef iid As Guid, ByRef ppv As IntPtr) As Integer

参数

pUnk
IntPtr

nativeint

要查询的接口。

iid
Guid

请求的接口的接口标识符(IID)。

ppv
IntPtr

nativeint

此方法返回时,包含对返回接口的引用。

返回

指示调用成功或失败的 HRESULT。

属性

注解

该方法 QueryInterface 公开 COM 对象的 IUnknown::QueryInterface 方法,该方法尝试获取特定的接口指针。 在 QueryInterface COM 对象上使用与在托管代码中执行强制转换操作相同。 使用此方法调用对象会导致引用计数在返回指针之前在接口指针上递增。 完成指针后,始终用于 Marshal.Release 递减引用计数。 若要获取表示 IntPtrIUnknown 接口指针的值,可以调用 Marshal.GetComInterfaceForObjectMarshal.GetIUnknownForObjectMarshal.GetIDispatchForObject

适用于

另请参阅