![]()
The new value of the reference count on the pUnk parameter.
The common language runtime manages the reference count of a COM object for you, making it unnecessary to use this method directly. In rare cases, such as testing a custom marshaler, you might find it necessary to manipulate an object's lifetime manually. After calling Marshal.AddRef(IntPtr), you must decrement the reference count by using a method such as Marshal.Release(IntPtr). Do not rely on the return value of Marshal.AddRef(IntPtr), as it can sometimes be unstable.
You can call Marshal.GetComInterfaceForObject(object, Type), Marshal.GetIUnknownForObject(object), or Marshal.GetIDispatchForObject(object) to obtain an IntPtr value that represents an tp://go.microsoft.com/fwlink/?LinkId=148003 interface pointer. You can also use these methods and the Marshal.AddRef(IntPtr) method on managed objects to obtain the COM interfaces represented by the managed object's COM callable wrapper. If you are not familiar with the details of this wrapper type, see [<topic://cpconcomcallablewrapper>].