Marshal.GetITypeInfoForType(Type) メソッド

定義

マネージド型から ITypeInfo インターフェイスを返します。

public:
 static IntPtr GetITypeInfoForType(Type ^ t);
public static IntPtr GetITypeInfoForType (Type t);
[System.Security.SecurityCritical]
public static IntPtr GetITypeInfoForType (Type t);
static member GetITypeInfoForType : Type -> nativeint
[<System.Security.SecurityCritical>]
static member GetITypeInfoForType : Type -> nativeint
Public Shared Function GetITypeInfoForType (t As Type) As IntPtr

パラメーター

t
Type

要求されている ITypeInfo インターフェイスを持つ型。

戻り値

IntPtr

nativeint

t パラメーターの ITypeInfo インターフェイスへのポインター。

属性

例外

t は COM から参照できる型ではありません。

または

tはWindows ランタイム型です。

型を格納するアセンブリのタイプ ライブラリが登録されていますが、型定義が見つかりません。

次の例では、 メソッドを使用して型の ITypeInfo インターフェイスへのポインターを取得する方法を GetITypeInfoForType 示します。

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

注釈

このメソッドは、元の型に基づく実装への ITypeInfo ポインターを返します。 を使用 GetITypeInfoForType して オブジェクトを呼び出すと、ポインターが返される前に、インターフェイス ポインターで参照カウントがインクリメントされます。 ポインターが終了したら、参照カウントをデクリメントするには、常に を使用 Marshal.Release します。 を適用 System.Runtime.InteropServices.MarshalAsAttribute して、標準の相互運用マーシャリング動作をこのカスタム マーシャラーに置き換えることができます。

適用対象

こちらもご覧ください