1 out of 1 rated this helpful - Rate this topic

SafeRelease

Many of the code examples in this documentation use the following function to release COM interface pointers.


template <class T> void SafeRelease(T **ppT)
{
    if (*ppT)
    {
        (*ppT)->Release();
        *ppT = NULL;
    }
}


Note  This function is not defined in an SDK header. To use this function, you must define it in your own code.

This function releases the pointer ppT and sets it equal to NULL.

Another option is to use a smart pointer class, such as CComPtr, which is defined in the Active Template Library (ATL).

Related topics

IUnknown::Release

 

 

Send comments about this topic to Microsoft

Build date: 3/6/2012

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ