Judson Valeski wrote:

> Judson Valeski wrote:
>> nsresult rv = NS_OK;
>> mChrome = do_QueryInterface(browserImpl, rv);
>> if (NS_FAILED(rv)) return rv;
> 
> Apologies. The above QI will not compile. do_QueryInterface()
> (http://lxr.mozilla.org/mozilla/source/xpcom/base/nsCOMPtr.h#344) requires an 
>nsISupports
> derrived pointer chain (base class nsISupports). You'll have to do a cast
> (NS_STATIC_CAST). That sticks the cast back in, but maintains the ownership model we 
>want.

How about:

rv = browserImpl->QueryInterface(NS_GET_IID(what you want mChrome to 
be),(void**)&mChrome);

or if mChrome is nsCOMPtr replace (void**)&mChrome with 
getter_AddRefs(mChrome).
Also, scc has mentioned that:

nsCOMPtr<nsIFoo> foo = do_QueryInterface(someObject, rv);

can be made more efficient by:

nsCOMPtr<nsIFoo> foo(do_QueryInterface(someObject, rv));

i.e. replace the assignment with constructor. Results in fewer 
instructions. Works with other "do_" things as well.

-- 
   Heikki Toivonen


Reply via email to