hello, Assume that I have two nsCOMPtr, for example:
nsCOMPtr<nsISupports> p1; nsCOMPtr<MyInterface> p2;
How to determine whether they refer to the same object?
I guess that this might be trivial, but I dont know how to do it.
There are special rules to determine the equality of two objects in COM: the best reference for this sort of thing is the old book "Essential COM" by Don Box; I recommend that any serious COM or XPCOM programmer read and understand the first half of that book very thoroughly. The second half (which is more Microsoft COM specific) is less important.
In any case, the rule to follow is: you can only compare two interface pointers if they are nsISupports* that you have obtained via QueryInterface:
So you cannot compare
nsCOMPtr<nSISupports> p1; nsCOMPtr<MyInterface> p2;
if (p1 == p2) {
// BAD COMPARISON
}You have to do
nsCOMPtr<nsISupports> p2asisupports = do_QueryInterface(p2);
if (p1 == psasisupports) {
// GOOD COMPARISON
}--BDS _______________________________________________ Mozilla-xpcom mailing list [email protected] http://mail.mozilla.org/listinfo/mozilla-xpcom
