语言

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

指向参数接口的ITypeInfo指针t。

属性

例外

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 此自定义封送处理器替换标准互操作封送行为。

适用于

另请参阅