QueryInterface should return S_OK on success and set the object pointer to NULL on failure. This is similar to the patch Ivan submitted a while ago for wined3d.
Oliver Stieber).