The following code example shows how to use the IDirect3DDevice9::GetDepthStencilSurface method to retrieve a pointer to the depth-buffer surface owned by the device.
LPDIRECT3DSURFACE9 pZBuffer; m_d3dDevice->GetDepthStencilSurface( &pZBuffer );