Επεξεργασία

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


Marshal.CreateWrapperOfType Method

Definition

Overloads

CreateWrapperOfType(Object, Type)
Obsolete.

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

CreateWrapperOfType<T,TWrapper>(T)

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

CreateWrapperOfType(Object, Type)

Source:
Marshal.NoCom.cs
Source:
Marshal.NoCom.cs
Source:
Marshal.NoCom.cs

Caution

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

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);
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
public static object? CreateWrapperOfType (object? o, Type t);
[System.Security.SecurityCritical]
public static object CreateWrapperOfType (object o, Type t);
public static object CreateWrapperOfType (object o, Type t);
public static object? CreateWrapperOfType (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>]
static member CreateWrapperOfType : obj * Type -> obj
[<System.Runtime.Versioning.SupportedOSPlatform("windows")>]
static member CreateWrapperOfType : obj * Type -> obj
[<System.Security.SecurityCritical>]
static member CreateWrapperOfType : obj * Type -> obj
static member CreateWrapperOfType : obj * Type -> obj
Public Shared Function CreateWrapperOfType (o As Object, t As Type) As Object

Parameters

o
Object

The object to be wrapped.

t
Type

The type of wrapper to create.

Returns

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

Attributes

Exceptions

t must derive from __ComObject.

-or-

t is a Windows Runtime type.

The t parameter is null.

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.

See also

Applies to

CreateWrapperOfType<T,TWrapper>(T)

Source:
Marshal.NoCom.cs
Source:
Marshal.NoCom.cs
Source:
Marshal.NoCom.cs

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);
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
public static TWrapper CreateWrapperOfType<T,TWrapper> (T? o);
public static TWrapper CreateWrapperOfType<T,TWrapper> (T o);
[<System.Security.SecurityCritical>]
static member CreateWrapperOfType : 'T -> 'Wrapper
[<System.Runtime.Versioning.SupportedOSPlatform("windows")>]
static member CreateWrapperOfType : 'T -> 'Wrapper
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
T

The object to be wrapped.

Returns

TWrapper

The newly wrapped object.

Attributes

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.

Applies to