Επεξεργασία

Κοινή χρήση μέσω


Marshal.GetTypedObjectForIUnknown(IntPtr, Type) Method

Definition

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

public:
 static System::Object ^ GetTypedObjectForIUnknown(IntPtr pUnk, Type ^ t);
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
public static object GetTypedObjectForIUnknown (IntPtr pUnk, Type t);
public static object GetTypedObjectForIUnknown (IntPtr pUnk, Type t);
[System.Security.SecurityCritical]
public static object GetTypedObjectForIUnknown (IntPtr pUnk, Type t);
[<System.Runtime.Versioning.SupportedOSPlatform("windows")>]
static member GetTypedObjectForIUnknown : nativeint * Type -> obj
static member GetTypedObjectForIUnknown : nativeint * Type -> obj
[<System.Security.SecurityCritical>]
static member GetTypedObjectForIUnknown : nativeint * Type -> obj
Public Shared Function GetTypedObjectForIUnknown (pUnk As IntPtr, t As Type) As Object

Parameters

pUnk
IntPtr

nativeint

A pointer to the IUnknown interface of the unmanaged object.

t
Type

The type of the requested managed class.

Returns

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

Attributes

Exceptions

t is not attributed with ComImportAttribute.

-or-

t is a Windows Runtime type.

Remarks

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.

Applies to

See also