You are currently viewing a snapshot of taken on April 21, 2008. Most of this content is highly out of date (some pages haven't been updated since the project began in 1998) and exists for historical purposes only. If there are any pages on this archive site that you think should be added back to, please file a bug.

Creating XPCOM Components Errata

by Doug Turner and Ian Oeschger

Chapter 1

On page 15, the implementation of QueryInterface should be as follows:

// typical, generic implementation of QI
NS_IMETHODIMP Sample::QueryInterface(const nsIID &aIID,
                                     void **aResult)
   if (aResult == NULL) {
   *aResult = NULL;
   if (aIID.Equals(kISupportsIID)) {
     *aResult = (void *) this;
   if (*aResult == NULL) {   // <-------------------------------------
   // add a reference
   return NS_OK;

Note that you only want to return and error in the |*aResult| is null.  In the text, the wrong logic was used.  Also note that this error made it into the webLock1.cpp code listing

Chapter 2

Under the "Using XPCOM Components in Your C++" section.  Above Figure 4, "Figure 4 duplicates code from Figure 5, but in C++ instead of JavaScript." should read "Figure 4 duplicates code from Figure 2, but in C++ instead of JavaScript." 

Chapter 3

Under "Three Parts for a XPCOM Component Library", the second to last paragraph, I refer to nsISupports and nsISupport.

Page 65, the code snippet is missing a closing ')' in the call to QI.  It should read:
nsIComponentRegistrar* compReg = nsnull;
nsresult rv = aCompMgr-> QueryInterface(kIComponentRegistrarIID,(void**)& comp);
Use of NULL throughout this chapter should be read as "nsnull", Mozilla's cross platform null define -- yes, name space even null.
I also have used zero (0) instead of NULL, nsnull rather.  Forgive me.

Chapter 4

The constructor for the Sample class in weblock.cpp should be listed as:
   mRefCnt = 0;

The SampleModule::Release implementation "stabilizes" the reference count before calling delete.  This really isn't required for our module.  The idea here is that the destructor or object that know about "this" but don't have references to it has some assumption that the reference count is nonzero. 
The mozbot irc feature which hands out uuid's is no longer functioning. I have been told that there are a number of sites that have online tools that will generate a UUID such as: or

Chapter 5

In the Declarations Macros section, the word "eariler" is misspelled as "earilier".
Also, in this same section, NS_DECL_NSISUPPORTS should be NS_DECL_ISUPPORTS

The code for weblock2.cpp does compile,  make these changes:
  • Add #include "nsISupportsUtils.h"
  • Add a comma after ""
Under Module Implementation Macros, the first code snippet is missing a closing semicolon.

The Web Locking Interface (Page 105), should _not_ mark the attribute |sites| as readonly.

Page 109 - the method GetSites is listed twice.

Page 111 - In the section, Remote Files and nsIFile, the word "exists" should read "exist"

Chapter 9

Page 158 - The word "simple" should read "simply".

XPInstall scripts.  See for information and better samples. 

Chapter 6

There is a misspelling of the word "third" in the first sentence under the Scriptable Interfaces section.  

Thanks to

Many warm thanks to to the following people that have sent in comments:

chris sherlock
cla at

And many more.

Random Notes

HTML content is generated by Adobe Framemaker.  I can not help how bad it looks nor care to fix any layout errors with this content.  If it really is unreadable, try the PDF.  If that isn't an option let me know and I will send nasty letters to the smart folks at Adobe asking them for better HTML generation.

If you want to send a comment about the book, please use the PDF and cite the page number.