This should have some comments on what exactly is happening here. I assume one of the GetDevice calls in the presentD3DXX functions will fail? Are there any more explicit ways to differentiate which code path is supposed to be taken?