Marshal.QueryInterface(IntPtr, Guid, IntPtr) Method

Definition

Requests a pointer to a specified interface from a COM object.

C#
[System.Security.SecurityCritical]
public static int QueryInterface(IntPtr pUnk, ref Guid iid, out IntPtr ppv);
C#
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
public static int QueryInterface(IntPtr pUnk, ref Guid iid, out IntPtr ppv);
C#
public static int QueryInterface(IntPtr pUnk, ref Guid iid, out IntPtr ppv);
C#
public static int QueryInterface(IntPtr pUnk, in Guid iid, out IntPtr ppv);

Parameters

pUnk
IntPtr

The interface to be queried.

iid
Guid

The interface identifier (IID) of the requested interface.

ppv
IntPtr

When this method returns, contains a reference to the returned interface.

Returns

An HRESULT that indicates the success or failure of the call.

Attributes

Remarks

The QueryInterface method exposes the IUnknown::QueryInterface method of a COM object, which attempts to obtain a specific interface pointer. Using QueryInterface on a COM object is the same as performing a cast operation in managed code. Calling an object with this method causes the reference count to increment on the interface pointer before the pointer is returned. Always use Marshal.Release to decrement the reference count once you have finished with the pointer. To obtain an IntPtr value that represents a IUnknown interface pointer, you can call Marshal.GetComInterfaceForObject, Marshal.GetIUnknownForObject, or Marshal.GetIDispatchForObject.

Applies to

Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1
UWP 10.0

See also