I'm *extremely* new to XPCOM and COM concepts in general, but I'm confused by the weblock tutorial.
The weblock tutorial gives the following code as an example of how to implement a QueryInterface function:
class Sample: public nsISupports
{
private:
nsrefcnt mRefCnt;public:
Sample();
virtual ~Sample(); NS_IMETHOD QueryInterface(const nsIID &aIID, void **aResult);
NS_IMETHOD_(nsrefcnt) AddRef(void);
NS_IMETHOD_(nsrefcnt) Release(void);};
Sample::Sample()
{
mRefCnt(0);
}Sample::~Sample()
{
}NS_IMETHODIMP Sample::QueryInterface(const nsIID &aIID,
void **aResult)
{
if (aResult == NULL)
{
return NS_ERROR_NULL_POINTER;
}
*aResult = NULL; if (aIID.Equals(kISupportsIID))
{
*aResult = (void *) this;
} if (aResult != NULL)
{
return NS_ERROR_NO_INTERFACE;
}
AddRef();
return NS_OK;
}NS_IMETHODIMP_(nsrefcnt) Sample::AddRef()
{
return ++mRefCnt;
}NS_IMETHODIMP_(nsrefcnt) Sample::Release()
{
if (--mRefCnt == 0)
{
delete this;
return 0;
}return mRefCnt; }
I'm a bit confused about the code in QueryInterface:
if (aResult != NULL)
{
return NS_ERROR_NO_INTERFACE;
}
Shouldn't aResult contain a reference to an interface? Why isn't this code something like "if (aResult == NULL)" ??
_______________________________________________ Mozilla-xpcom mailing list [EMAIL PROTECTED] http://mail.mozilla.org/listinfo/mozilla-xpcom
