Marshal.GetITypeInfoForType(Type) 方法

定義

從 Managed 型別傳回 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 執行階段類型。

包含型別之組件的型別程式庫已註冊,但找不到型別定義。

範例

下列範例示範如何使用 方法來擷取型 GetITypeInfoForType 別介面的 ITypeInfo 指標。

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 以使用此自訂封送處理器取代標準 Interop 封送處理行為。

適用於

另請參閱