Marshal.CreateWrapperOfType Marshal.CreateWrapperOfType Marshal.CreateWrapperOfType Marshal.CreateWrapperOfType Method

Definition

Overloads

CreateWrapperOfType(Object, Type) CreateWrapperOfType(Object, Type) CreateWrapperOfType(Object, Type) CreateWrapperOfType(Object, Type)

Wraps the specified COM object in an object of the specified type.

CreateWrapperOfType<T,TWrapper>(T) CreateWrapperOfType<T,TWrapper>(T) CreateWrapperOfType<T,TWrapper>(T) CreateWrapperOfType<T,TWrapper>(T)

[Supported in the .NET Framework 4.5.1 and later versions]

Wraps the specified COM object in an object of the specified type.

CreateWrapperOfType(Object, Type) CreateWrapperOfType(Object, Type) CreateWrapperOfType(Object, Type) CreateWrapperOfType(Object, Type)

Warning

This API is now obsolete.

Wraps the specified COM object in an object of the specified type.

public:
 static System::Object ^ CreateWrapperOfType(System::Object ^ o, Type ^ t);
[System.Obsolete("CreateWrapperOfType(Object, Type) may be unavailable in future releases. Instead, use CreateWrapperOfType<T,T2>(T). For more info, go to http://go.microsoft.com/fwlink/?LinkID=296519")]
[System.Security.SecurityCritical]
public static object CreateWrapperOfType (object o, Type t);
static member CreateWrapperOfType : obj * Type -> obj
Public Shared Function CreateWrapperOfType (o As Object, t As Type) As Object
Parameters
o
Object Object Object Object

The object to be wrapped.

t
Type Type Type Type

The type of wrapper to create.

Returns

The newly wrapped object that is an instance of the desired type.

Exceptions

t must derive from __ComObject.

-or-

t is a Windows Runtime type.

o cannot be converted to the destination type because it does not support all required interfaces.

Remarks

CreateWrapperOfType converts one COM class type, typically the base __ComObject type, to another COM class type. The input COM object, represented by parameter o, is a Runtime Callable Wrapper (RCW).

Both the t and o parameters must be classes whose signatures are attributed with System.Runtime.InteropServices.ComImportAttribute. The Tlbimp.exe (Type Library Importer) tool applies this attribute for you when it imports a type library. If you create the RCW manually in source code, you should apply this attribute to the managed signature that represents the original coclass to signify its COM origins.

Tlbimp.exe imports a COM coclass as a managed class and an interface. The coclass interface has the same name as the original coclass, and the managed class has the original coclass name appended with "Class". For example, a coclass called MyCoclass becomes a coclass interface called MyCoclass and a managed class called MyCoclassClass. Since t must be a class, not an interface, be sure to specify the managed class (MyCoclassClass) and not the coclass interface.

Note

You lose the identity of the input COM object because a new RCW instance wraps the IUnknown pointer exposed by the original RCW.

Security

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

See Also

CreateWrapperOfType<T,TWrapper>(T) CreateWrapperOfType<T,TWrapper>(T) CreateWrapperOfType<T,TWrapper>(T) CreateWrapperOfType<T,TWrapper>(T)

[Supported in the .NET Framework 4.5.1 and later versions]

Wraps the specified COM object in an object of the specified type.

public:
generic <typename T, typename TWrapper>
 static TWrapper CreateWrapperOfType(T o);
[System.Security.SecurityCritical]
public static TWrapper CreateWrapperOfType<T,TWrapper> (T o);
static member CreateWrapperOfType : 'T -> 'Wrapper
Public Shared Function CreateWrapperOfType(Of T, TWrapper) (o As T) As TWrapper
Type Parameters
T

The type of object to wrap.

TWrapper

The type of object to return.

Parameters
o

The object to be wrapped.

Returns

The newly wrapped object.

Exceptions

T must derive from __ComObject.

-or-

T is a Windows Runtime type.

o cannot be converted to the TWrapper because it does not support all required interfaces.

Remarks

CreateWrapperOfType<T,TWrapper>(T) converts a COM object of type T to the TWrapper COM class type. The input COM object, represented by parameter o, is a Runtime Callable Wrapper (RCW).

Both the T generic type parameter and the o parameter must be classes whose signatures are attributed with the System.Runtime.InteropServices.ComImportAttribute attribute. The Tlbimp.exe (Type Library Importer) tool applies this attribute for you when it imports a type library. If you create the RCW manually in source code, you should apply this attribute to the managed signature that represents the original coclass to signify its COM origins.

Tlbimp.exe imports a COM coclass as a managed class and an interface. The coclass interface has the same name as the original coclass, and the managed class has the original coclass name appended with "Class". For example, a coclass called MyCoclass becomes a coclass interface called MyCoclass and a managed class called MyCoclassClass. BecauseT must be a class, not an interface, be sure to specify the managed class (MyCoclassClass) and not the coclass interface.

Note

You lose the identity of the input COM object, because a new RCW instance wraps the IUnknown pointer exposed by the original RCW.

Security

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

Applies to