Freigeben über


Marshal.GetITypeInfoForType-Methode: (Type)

 

Veröffentlicht: Juli 2016

Gibt eine System.Runtime.InteropServices.ComTypes.ITypeInfo-Schnittstelle aus einem verwalteten Typ zurück.

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

Syntax

[SecurityCriticalAttribute]
public static IntPtr GetITypeInfoForType(
    Type t
)
public:
[SecurityCriticalAttribute]
static IntPtr GetITypeInfoForType(
    Type^ t
)
[<SecurityCriticalAttribute>]
static member GetITypeInfoForType : 
        t:Type -> nativeint
<SecurityCriticalAttribute>
Public Shared Function GetITypeInfoForType (
    t As Type
) As IntPtr

Parameter

  • t
    Type: System.Type

    Der Typ, dessen ITypeInfo-Schnittstelle angefordert wird.

Rückgabewert

Type: System.IntPtr

Ein Zeiger auf die ITypeInfo-Schnittstelle für den t-Parameter.

Ausnahmen

Exception Condition
ArgumentException

t ist kein für COM sichtbarer Typ.

- oder -

t ist ein Windows-Runtime-Typ.

COMException

Für die Assembly ist eine Typbibliothek registriert, die den Typ enthält, aber die Typdefinition wurde nicht gefunden.

Hinweise

This method returns a pointer to an ITypeInfo implementation that is based on the original type. Calling an object with M:System.Runtime.InteropServices.Marshal.GetITypeInfoForType(System.Type) causes the reference count to increment on the interface pointer before the pointer is returned. Always use M:System.Runtime.InteropServices.Marshal.Release(System.IntPtr) to decrement the reference count once you have finished with the pointer. You can apply the T:System.Runtime.InteropServices.MarshalAsAttribute to replace standard interop marshaling behavior with this custom marshaler.

Beispiele

The following example demonstrates how to retrieve a pointer to the ITypeInfo interface for a type using the M:System.Runtime.InteropServices.Marshal.GetITypeInfoForType(System.Type) method.

using System;
using System.Runtime.InteropServices;

class Program
{

    static void Run()
    {
        Console.WriteLine("Calling Marshal.GetITypeInfoForType...");

        // Get the ITypeInfo pointer for an Object type
        IntPtr pointer = Marshal.GetITypeInfoForType(typeof(object));

        Console.WriteLine("Calling Marshal.Release...");

        // Always call Marshal.Release to decrement the reference count.
        Marshal.Release(pointer);
    }

    static void Main(string[] args)
    {
        Run();
    }
}
Imports System.Runtime.InteropServices

Module Program


    Sub Run()

        ' Dim a pointer
        Dim pointer As IntPtr

        Console.WriteLine("Calling Marshal.GetIUnknownForObjectInContext...")

        ' Get the ITypeInfo pointer for an Object type
        pointer = Marshal.GetITypeInfoForType(Type.GetType("System.Object"))

        Console.WriteLine("Calling Marshal.Release...")

        ' Always call Marshal.Release to decrement the reference count.
        Marshal.Release(pointer)



    End Sub

    Sub Main(ByVal args() As String)

        Run()

    End Sub

End Module

Sicherheit

SecurityCriticalAttribute

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

Versionsinformationen

.NET Framework
Verfügbar seit 1.1

Siehe auch

GetTypeForITypeInfo
MarshalAsAttribute
Marshal-Klasse
System.Runtime.InteropServices-Namespace

Zurück zum Anfang