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 方法,嘗試取得特定的介面指標。 在 COM 物件上使用 QueryInterface ,與在受管程式碼中執行 cast 操作相同。 使用此方法呼叫物件會使介面指標的參考數量增加,然後指標才回傳。 每次用指標完成後,都要用 Marshal.Release 來減少參考數量。 若要取得 IntPtr 代表 IUnknown 介面指標的值,你可以呼叫 Marshal.GetComInterfaceForObjectMarshal.GetIUnknownForObject、 或 Marshal.GetIDispatchForObject

適用於

另請參閱