I am interested in comparing two IDirect3DDevice9
COM pointers, which inherit IUnknown
, for equality. Based on a similar topic, I understand you can QI
IUnknown
for both pointers, and compare the result for equality. However, I am curious if we can accomplish the same thing via an IsEqual
method that directly takes two IUnknown
pointers, let inheritance determine the relevant IUnknown
pointers, and use that for the equality check instead. Based on my experiment, that seems to work and doesn't require the QI
and release
operation (or maybe that's done implicitly). If there's any caveats that warrant this suggestion invalid, please let me know.
BOOL IsEqual(IUnknown *pA, IUnknown *pB)
{
return (pA == pB);
}
BOOL IsEqual (IDirect3DDevice9 *pDevice1, IDirect3DDevice9 *pDevice2)
{
IUnknown *u1, *u2;
pDevice1->QueryInterface(IID_IUnknown, &u1);
pDevice2->QueryInterface(IID_IUnknown, &u2);
BOOL areSame = u1 == u2;
u1->Release();
u2->Release();
return areSame;
}