Important:
This is retired content. This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This content may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.
4/8/2010

The AddRefmethod increments the reference count for an interface on an object. It should be called for every new copy of a pointer to an interface on a given object.

Syntax

ULONG AddRef(void);

Parameters

None.

Return Value

Returns an integer from 1 to n, representing the value of the new reference count. This information for diagnostic or testing purposes only because, in certain situations, the value may be unstable.

Remarks

Objects use a reference counting mechanism to ensure that the lifetime of the object includes the lifetime of references to it. You use AddRefto stabilize a copy of an interface pointer. AddRefcan also be called when the life of a cloned pointer must extend beyond the lifetime of the original pointer. The cloned pointer must be released by calling MAPI IUnknown::Release.

Objects must be able to maintain (231)-1 outstanding pointer references. Therefore, the internal reference counter that AddRefmaintains must be a 32-bit unsigned integer.

Call this function for every new copy of an interface pointer that you make. For example, if you are passing a copy of a pointer back from a function, you must call AddRefon that pointer. You must also call AddRefon a pointer before passing it as an in-out parameter to a function; the function calls MAPI IUnknown::Releasebefore copying the out-value on top of it.

Requirements

Header unknwn.h
Windows Embedded CE Windows CE 3.0 and later
Windows Mobile Pocket PC 2002 and later, Smartphone 2002 and later

See Also