how to implement nsIWepProgressListener in C++

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

how to implement nsIWepProgressListener in C++

Christian Sell
Hello,

I have the following class declaration:

class MyLocationListener: public nsIWebProgressListener
{
public:
 MyLocationListener();
 virtual ~MyLocationListener();
 NS_DECL_ISUPPORTS
 NS_DECL_NSIWEBPROGRESSLISTENER
};

and the corresponding implementation. I am using this class in the following way:

MyLocationListener * listener = new MyLocationListener();

nsCOMPtr<nsIWeakReference> weakref = do_GetWeakReference(listener, &retval);
CHECKERR();
retval = browser->AddWebBrowserListener(weakref, NS_GET_IID(nsIWebProgressListener));
CHECKERR();

however, the do_GetWeakReference call fails with an NS_ERROR_NO_INTERFACE error code. Can someone point out to me how to fix that? I tried to add a nsIWeakReference superclass to the class decl, including the NS_DECL_xx macros, but that yielded compile errors that I was notable to decipher. Maybe someone has a quick hint, or link..

TIA,
Christian
_______________________________________________
dev-embedding mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-embedding
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: how to implement nsIWepProgressListener in C++

Christian Sell
ok, I have finally managed. Heres the code:

//class decl
class LocationListener: public nsIWebProgressListener, public nsSupportsWeakReference
{
public:
  LocationListener();
  virtual ~LocationListenerW();
  NS_DECL_ISUPPORTS
  NS_DECL_NSIWEBPROGRESSLISTENER
};

//class impl
NS_IMPL_ISUPPORTS2(LocationListener, nsIWebProgressListener, nsISupportsWeakReference)

NS_IMETHODIMP LocationListener::OnXXChange(...)
{
        return NS_OK;
}

//and class usage. plistener must be created non-locally
LocationListener * listener = new LocationListener();
nsCOMPtr<nsISupports> plistener = static_cast<nsIWebProgressListener *>(listener);

nsCOMPtr<nsIWeakReference> weakref = do_GetWeakReference(plistener, &retval);
retval = browser->AddWebBrowserListener(weakref, NS_GET_IID(nsIWebProgressListener));
_______________________________________________
dev-embedding mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-embedding
Loading...