Chris Shen wrote:
> Components.classes["@mozilla.org/notifservice;1"].createInstance();
> notifserv = do_CreateInstance(NS_NOTIFSERVICE_CONTRACTID, &rv);
> I expect:
> At the runtime, my browser application loads the notifservice first and
> add itself as a listener to the service. By the time, I assume the
> notifservice
> remaining in memory. Then my browser app loads the test html page which
> loads
> the notifservice as well. Because the notifservice already registered in
> memory,
> I assume the xpconnect only increases the reference count rather than
> creates
> a new instance again.
do_CreateInstance (C++) and createInstance (JS) will always create a new
instance. To access (possibly instantiating, if none exists) a shared
service, use do_GetService (C++) and getService (JS) instead.
> The breakpoint never reaches nsNotifService's notif method. It seems tell me
> that
> loading the notifservice in js isn't successfully.
What's the error it gives? Did you put the typelib for the
nsINotifService in the components directory?
(We have nsIObserver for this sort of mechanism already, which you might
find requires you to write less new code -- you'd just need an
implementation of nsIObserver in C++, really, and there are lots to follow.)
Mike