Look at IDirect3DDevice9::GetDepthStencilSurface. It allows you to get the depth/stencil surface as a IDirect3DSurface9 object. Then use the GetDesc method of the surface to retrieve the format of the data.