Freigeben über


Marshal.CreateWrapperOfType-Methode: (Object, Type)

 

Umschließt das angegebene COM-Objekt mit einem Objekt des angegebenen Typs.

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

Syntax

[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

Parameter

  • t
    Type: System.Type

    Der Typ des zu erstellenden Wrappers.

Rückgabewert

Type: System.Object

Das neu umschlossene Objekt, das eine Instanz des gewünschten Typs darstellt.

Ausnahmen

Exception Condition
ArgumentException

t muss von __ComObject abgeleitet werden.

- oder -

t ist ein Windows-Runtime-Typ.

ArgumentNullException

Der t-Parameter ist null.

InvalidCastException

o kann nicht in den Zieltyp konvertiert werden, da es nicht alle erforderlichen Schnittstellen unterstützt.

Hinweise

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.

Hinweis

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.

Sicherheit

SecurityCriticalAttribute

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

Versionsinformationen

Universelle Windows-Plattform
Verfügbar seit 8
.NET Framework
Verfügbar seit 1.1
Portierbare Klassenbibliothek
Unterstützt in: portierbare .NET-Plattformen
Windows Phone
Verfügbar seit 8.1

Siehe auch

ComImportAttribute
CreateWrapperOfType Überladen
Marshal-Klasse
System.Runtime.InteropServices-Namespace

Zurück zum Anfang