Export (0) Print
Expand All

Marshal.GetTypedObjectForIUnknown Method

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
)

Parameters

pUnk
Type: System.IntPtr

A pointer to the IUnknown interface of the unmanaged object.

t
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.

ExceptionCondition
ArgumentException

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

-or-

t is a Windows Runtime type.

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 an IUnknown 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.

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

  • SecurityCriticalAttribute 

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

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.

Show:
© 2014 Microsoft