Método Marshal.CreateWrapperOfType (Object, Type)
Ajusta el objeto COM especificado en un objeto del tipo especificado.
Espacio de nombres: System.Runtime.InteropServices
Ensamblado: mscorlib (en mscorlib.dll)
Sintaxis
[SecurityCriticalAttribute]
public static object CreateWrapperOfType(
object o,
Type t
)
public:
[SecurityCriticalAttribute]
static Object^ CreateWrapperOfType(
Object^ o,
Type^ t
)
[<SecurityCriticalAttribute>]
static member CreateWrapperOfType :
o:Object *
t:Type -> Object
<SecurityCriticalAttribute>
Public Shared Function CreateWrapperOfType (
o As Object,
t As Type
) As Object
Parámetros
o
Type: System.ObjectObjeto que se va a almacenar en un contenedor.
t
Type: System.TypeTipo de contenedor que se va a crear.
Valor devuelto
Type: System.Object
Objeto recién ajustado que es una instancia del tipo deseado.
Excepciones
Exception | Condition |
---|---|
ArgumentException | t debe derivar de __ComObject. O bien t es un tipo Windows en tiempo de ejecución. |
ArgumentNullException | El parámetro t es null. |
InvalidCastException | o no se puede convertir en el tipo de destino, ya que no admite todas las interfaces requeridas. |
Comentarios
CreateWrapperOfType converts one COM class type, typically the generic __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 T: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.
Nota
You lose the identity of the input COM object because a new RCW instance wraps the IUnknownhttps://go.microsoft.com/fwlink/?LinkId=148003 pointer exposed by the original RCW.
Seguridad
requires full trust for the immediate caller. This member cannot be used by partially trusted or transparent code.
Información de versión
Plataforma universal de Windows
Disponible desde 8
.NET Framework
Disponible desde 1.1
Biblioteca de clases portable
Se admite en: plataformas portátiles de .NET
Windows Phone
Disponible desde 8.1
Ver también
ComImportAttribute
CreateWrapperOfType Sobrecarga
Clase Marshal
Espacio de nombres System.Runtime.InteropServices
Volver al principio