See below inline ...
Eremia A wrote:
> Hi...
> I'm a beginner to xpcom and I'd like to know the answer to some basic
> questions.
>
> 1. Here "somefunction" is a getter function.
>
<snip>
> Is this example below the right way to fix the problem?
>
> NS_IMETHODIMP SomeClass::somefunction( nsILocalFile ** aNewFile ) {
> nsresult rv;
> nsCOMPtr<nsILocalFile> aFile =
> o_CreateInstance( NS_LOCAL_FILE_CONTRACTID, &rv );
> aFile->InitWithPath( "/some/path/file" );
>
> nsILocalFile *dummy = aFile;
> NS_ADDREF( dummy );
>
> *aNewFile = dummy;
>
> return NS_OK;
> }
Short answer: yes that will work ... OR ... you could just
declare aFile as type "nsILocalFile *" instead of a smart
pointer and leave out the AddRef.
>
> 2. I created a nsMyWebProgressListener class, derived from
> nsIWebProgressListener. The nsMyWebProgressListener is used locally, it
> doesn't have to have a CID or IID. I need to pass a
> nsIWebProgressListener* to "SetWebProgressListener".
> Is there something wrong to code it this way?
>
> nsCOMPtr<nsIWebProgressListener> dummy = new nsMyWebProgressListener;
> aLauncher->SetWebProgressListener( dummy );
>
> Thanks.
Make sure you unregister the progress listener
before "dummy" goes out of scope.
-rick