Marshal.GetComInterfaceForObject Method (Object, Type, CustomQueryInterfaceMode)

Returns a pointer to an IUnknown interface that represents the specified interface on the specified object. Custom query interface access is controlled by the specified customization mode.

Namespace:  System.Runtime.InteropServices
Assembly:  mscorlib (in mscorlib.dll)

public static IntPtr GetComInterfaceForObject(
	Object o,
	Type T,
	CustomQueryInterfaceMode mode


Type: System.Object

The object that provides the interface.

Type: System.Type

The type of interface that is requested.

Type: System.Runtime.InteropServices.CustomQueryInterfaceMode

One of the enumeration values that indicates whether to apply an IUnknown::QueryInterface customization that is supplied by an ICustomQueryInterface.

Return Value

Type: System.IntPtr
The interface pointer that represents the interface for the object.


The T parameter is not an interface.


The type is not visible to COM.


The T parameter is a generic type.


The object o does not support the requested interface.


The o parameter is null.


The T parameter is null.

GetComInterfaceForObject(Object, Type, CustomQueryInterfaceMode) lets you specify whether to apply query interface customization. Use the GetComInterfaceForObject(Object, Type) overload to apply query interface customization by default.

.NET Framework

Supported in: 4.6, 4.5, 4

.NET Framework Client Profile

Supported in: 4

Portable Class Library

Supported in: Portable Class Library

.NET for Windows Store apps

Supported in: Windows 8

Obsolete (compiler warning) in Windows Phone 8.1

  • SecurityCriticalAttribute 

    requires full trust for the immediate caller. This member cannot be used by partially trusted or transparent code.

Windows Phone 8.1, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
© 2014 Microsoft