Marshal.GetComInterfaceForObject Method (Object, Type, CustomQueryInterfaceMode)

.NET Framework (current version)

The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

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 Shared Function GetComInterfaceForObject (
	o As Object,
	T As Type,
	mode As CustomQueryInterfaceMode
) As IntPtr


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.

Exception Condition

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.


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

Universal Windows Platform
Available since 8
.NET Framework
Available since 4.0
Portable Class Library
Supported in: portable .NET platforms
Windows Phone
Available since 8.1
Return to top