XPCOM FAQ

Get out your decoder rings kids!

Having a basic understanding of COM is only the first
step. To get CMonkey code to build and run,
you need to translate your COM ideas into Netscape
speak.

Feel free to add to this document or change incorrect info.
Hopefully more info and more examples will help new
people reach XPCOM nirvana more quickly.

To mentally translate XPCOM to COM.

vanilla COM | XPCOM
IUnknown | nsISupports
IClassFactory | nsIFactory
virtual void _stdcall | NS_IMETHOD
interface ID = IID | nsID = nsIID = IID
class ID = CLSID | nsCID = CID

Not too difficult.
But wait. There's more.
-------------------------------------------

Why don't those classes have AddRef?

Actually, those classes do have AddRef. It is hidden
in a macro. There are alot of macros that are alot of help
once you know :
1) They exist.

2) Where they are defined. (They aren't always mnemonic or onomatipeic.
You might want to print them out.)

mozilla/xpcom/public/nsCom.h
mozilla/xpcom/public/nsISupports.h

3)What they are
Here's a short list to give you an idea of what you've been missing.
The include files listed above are the real reference.

4) A quick way to expand pesky macros:
For macros in foo.cpp, 'make foo.i'

This will pump the foo.cpp file through C preprocessing
and expand all the macros for you. The output can be
hard to read, but if you search for unique strings
in the area you aredebugging, you can navigate
the file pretty easily.
(thanks to hshaw@netscape.com)

Netscape MACRO | Expansion of macro
NSADDREF(factoryinstname) | Factory->AddRef();
NS_IMETHOD | virtual nsresult __stdcall
NS_INIT_REFCNT() | mRefCnt = 0
NS_INIT_ISUPPORTS() | NS_INIT_REFCNT()
NS_DECL_ISUPPORTS | public: NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr); NS_IMETHOD_(nsrefcnt) AddRef(void); NS_IMETHOD_(nsrefcnt) Release(void); protected: nsrefcnt mRefCnt;

Useful Links to COM Documents:

XPCOM Page
nsCOMPtr
Coding Conventions
Getting BAMmed
How to COM
Modularization Techniques
C++ Portability Guide
NGLayout