The correct COM way to do this is to query interface with IUnknown. A quote from the remarks here in MSDN:
For any one object, a specific query for the IUnknown interface on any
of the object's interfaces must always return the same pointer value.
This enables a client to determine whether two pointers point to the
same component by calling QueryInterface with IID_IUnknown and
comparing the results. It is specifically not the case that queries
for interfaces other than IUnknown (even the same interface through
the same pointer) must return the same pointer value.
So the correct code is
BOOL IsEqual (ID3D11Texture2D *pTexture1, ID3D11Texture2D *pTexture2)
{
IUnknown *u1, *u2;
pTexture1->QueryInterface(IID_IUnknown, &u1);
pTexture2->QueryInterface(IID_IUnknown, &u2);
BOOL areSame = u1 == u2;
u1->Release();
u2->Release();
return areSame;
}
Update
- Added a call to Release so decrease reference counts. Thanks for the good comments.
- You can also use ComPtr for this job. Please look in MSDN.