I am not, do not aspire to, nor ever will be, a DirectX programmer.
But, as a C programmer, I can tell you that your error checking can fail silently. I don't know exactly what that code is supposed to do, but it's possible a number of the lines never run due to an error, with no error being reported.
As a graphics programmer, I'll tell you that screen tearing is often caused by a lack of synchronization between the update rate and the refresh rate. It sounded like you already knew that.