perhaps with a if (--pipe->dwRefCount != 0) return TRUE

we would have less if() levels...