Marshal::GetTypedObjectForIUnknown Method (IntPtr, Type^)

 
System_CAPS_noteNote

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

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

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

public:
[SecurityCriticalAttribute]
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.

Exception Condition
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 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.

SecurityCriticalAttribute

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
Show: