On 12/2/09 7:01 AM, Blaine Monkey wrote:
I defined the NS_STATIC_CAST in main.cpp code because isn't defined in
nscore.h. [#define NS_STATIC_CAST(__type, __ptr) static_cast< __type
(__ptr)]
Indeed, we removed NS_STATIC_CAST and recommend that people just use
static_cast<type>() directly.
What am I doing wrong? The code below:
I don't see your implementation of addref/release/queryinterface here. Are
you using NS_IMPL_ISUPPORTS1 or some hand-rolled code to implement those
methods?
nsCOMPtr<MyBrowserProgressListener> ml;
nsCOMPtr<nsIWeakReference>
listener(do_GetWeakReference(NS_STATIC_CAST(nsIWebProgressListener*, ml)));
This code is definitely incorrect. You've declared a
nsCOMPtr<MyBrowserProgressListener> ml; but you haven't actually *created* a
MyBrowserProgressListener. Did you perhaps mean:
nsCOMPtr<MyBrowserProgressListener> ml = new MyBrowserProgresListener();
Then you try to get a weak reference to your listener. I'm not sure why
you're trying to do this, but your MyBrowserProgressListener class doesn't
implement nsISupportsWeakReference and so do_GetWeakReference will
undoubtedly fail, leaving `listener` null. The typical and recommended way
to implement nsISupportsWeakReference is to inherit from
nsSupportsWeakReference and make sure your QueryInterface implementation
lists nsISupportsWeakReference.
--BDS
_______________________________________________
dev-embedding mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-embedding