Marshal.GetComInterfaceForObject Method (Object, Type)
Returns a pointer to an IUnknown interface that represents the specified interface on the specified object. Custom query interface access is enabled by default.
Assembly: mscorlib (in mscorlib.dll)
- Type: System.Object
The object that provides the interface.
- Type: System.Type
The type of interface that is requested.
Return ValueType: System.IntPtr
The interface pointer that represents the specified interface for the object.
This method returns an interface pointer that represents the requested interface on the specified object. It is particularly useful if you have an unmanaged method that expects to be passed an interface pointer. 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. You must adhere to the rules defined by COM when using raw COM interface pointers.
is useful when calling a method that exposes a COM object parameter as an IntPtr type, or with custom marshaling. Although less common, you can use this method on a managed object to obtain a pointer to the object's COM callable wrapper. For example, you can use on a managed object that is exported to COM to obtain an interface pointer for System.Runtime.InteropServices.UCOMIConnectionPointContainer. You cannot obtain a pointer to a class interface since a class interface lacks the corresponding type to pass to the second parameter (t). Instead, use Marshal.GetIDispatchForObject to invoke the members on the default interface of the COM callable wrapper, which is usually an auto-dispatch class interface.
The method overload allows query interface customization by default. To specify whether to apply query interface customization, use the GetComInterfaceForObject(Object, Type, CustomQueryInterfaceMode) method overload.
requires full trust for the immediate caller. This member cannot be used by partially trusted or transparent code.