Marshal.AddRef(IntPtr) 方法

定义

递增指定接口上的引用计数。

public:
 static int AddRef(IntPtr pUnk);
[System.Security.SecurityCritical]
public static int AddRef (IntPtr pUnk);
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
public static int AddRef (IntPtr pUnk);
public static int AddRef (IntPtr pUnk);
[<System.Security.SecurityCritical>]
static member AddRef : nativeint -> int
[<System.Runtime.Versioning.SupportedOSPlatform("windows")>]
static member AddRef : nativeint -> int
static member AddRef : nativeint -> int
Public Shared Function AddRef (pUnk As IntPtr) As Integer

参数

pUnk
IntPtr

nativeint

要递增的接口引用计数。

返回

Int32

pUnk 参数上的引用计数的新值。

属性

注解

公共语言运行时为你管理 COM 对象的引用计数,因此不需要直接使用此方法。 在极少数情况下(例如测试自定义封送器),你可能会发现需要手动操作对象的生存期。 调用 AddRef后,必须使用如下 Marshal.Release方法递减引用计数。 不要依赖于返回值 AddRef,因为它有时可能不稳定。

可以调用Marshal.GetComInterfaceForObjectMarshal.GetIUnknownForObjectMarshal.GetIDispatchForObject获取表示 IntPtr IUnknown 接口指针的值。 还可以使用这些方法和 AddRef 托管对象的方法来获取托管对象的 COM 可调用包装器表示的 COM 接口。 如果不熟悉此包装器类型的详细信息,请参阅 COM 可调用包装器

适用于

另请参阅