Google Ryhmät ei enää tue uusia Usenet-postauksia tai ‐tilauksia. Aiempi sisältö on edelleen nähtävissä.

how to implement nsIWepProgressListener in C++

30 katselukertaa
Siirry ensimmäiseen lukemattomaan viestiin

Christian Sell

lukematon,
20.2.2014 klo 12.33.4920.2.2014
vastaanottaja
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

Christian Sell

lukematon,
24.2.2014 klo 6.15.1424.2.2014
vastaanottaja
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);
0 uutta viestiä