>> I think it is better to detect instances of your object using
>> QueryInterface rather than trust the cid. You can simply declare an
>> iid locally in your implmentation and have the QI method respond with
>> a pointer to your base object when QI'd for that iid. I think this is
>> safer and has no more overhead than what you propose.
>
>
>
> Ah, this really reduces the amount of involved code
> to 4 lines (.. nsIClassInfo is out) - nice!
>
> I'm still using the cid, but now the actual casting is done
> in a custom QI impl :
>
>
> NS_IMETHODIMP
> btCBuffer::QueryInterface (REFNSIID aIID, void** aInstancePtr)
> {
> // ..
> if ( aIID.Equals(this->GetCID()) ) {
> *aInstancePtr = this;
> return NS_OK;
> }
> // ..
>
probably, its better to stick with normal QI semantics and
AddRef also in this case:
if ( aIID.Equals(this->GetCID()) ) {
*aInstancePtr = this;
NS_ADDREF(this);
return NS_OK;
}
.. and use it ..
btCBuffer* _buf;
rv = otherBuffer->QueryInterface (this->GetCID(), &_buf);
if (NS_FAILED(rv)) { // implementation class different
}
else { // implementation class identical
_buf->Release ();
}
this will result in more code executed as one now has also
to Release(), but it maybe has two points on it's side:
1. QI behaves as always (it returns something AddRef'ed)
2. the obj will not fade away unexpectedly
Tobias.