GetTypedObjectForIUnknown Method
Collapse the table of content
Expand the table of content

Marshal.GetTypedObjectForIUnknown Method (IntPtr, Type)


Returns a managed object of a specified type that represents a COM object.

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

public static object GetTypedObjectForIUnknown(
	IntPtr pUnk,
	Type t


Type: System.IntPtr

A pointer to the IUnknown interface of the unmanaged object.

Type: System.Type

The type of the requested managed class.

Return Value

Type: System.Object

An instance of the class corresponding to the Type object that represents the requested unmanaged COM object.

Exception Condition

t is not attributed with System.Runtime.InteropServices.ComImportAttribute.


t is a Windows Runtimetype.

The t parameter must be either a COM-imported type or a subtype of a COM-imported type. In addition, t must be a type whose metadata was imported by the Tlbimp.exe (Type Library Importer) tool. This type must be a class and not an associated coclass interface, which carries the name of the COM class. For example, if Tlbimp.exe imports Myclass as a class called MyclassClass and as a coclass interface called Myclass, you must use MyclassClass (not Myclass) with this method. For additional information about imported classes and coclass interfaces, see Imported Type Conversion.

If an object has already been obtained for the pUnk parameter, t is ignored and the existing object is returned. pUnk represents anIUnknown interface pointer; however, because all COM interfaces derive directly or indirectly from IUnknown, you can pass any COM interface to this method. The object returned by GetTypedObjectForIUnknown is a Runtime Callable Wrapper (RCW), which the common language runtime manages as it does any other managed object.


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

.NET Framework
Available since 1.1
Return to top
© 2015 Microsoft