The stencil buffer enables or disables drawing to the rendering target surface on a pixel-by-pixel basis. At its most fundamental level, it enables applications to mask off sections of the rendered image so that it is not displayed. Applications often use stencil buffers for special effects such as dissolves, decaling, and outlining. For details, see Stencil Buffer Techniques.
Stencil buffer information is embedded in the z-buffer data. Your application can test the user's hardware to see if it supports stencil buffers by invoking the IDirect3D3::EnumZBufferFormats method. To obtain information about the particular format of the z-buffer data, call the IDirectDrawSurface4::GetPixelFormat method, which passes a DDPIXELFORMAT structure to your application. The relevant information is in the dwZBufferBitDepth, dwStencilBitDepth, dwZBitMask, and dwStencilBitMask members.