Marshal.AddRef(IntPtr) 方法

定义

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

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

参数

pUnk
IntPtr

nativeint

要递增的接口引用计数。

返回

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

属性

注解

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

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

适用于

另请参阅