gecko-dev/xpcom/doc/xpcom_faq.html

162 строки
5.4 KiB
HTML

<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Author" content="pnunn">
<meta name="GENERATOR" content="Mozilla/4.5 [en]C-NSCP (WinNT; U) [Netscape]">
<title>xpCom FAQ</title>
</head>
<body>
<b><font size=+3>XPCOM FAQ</font></b>
<p>Get out your decoder rings kids!
<p>Having a basic understanding of COM is only the first
<br>step. To get CMonkey code to build and run,
<br>you&nbsp; need to translate your COM ideas into Netscape
<br>speak.
<p>Feel free to add to this document or change incorrect info.
<br>Hopefully more info and more examples will help new
<br>people reach XPCOM nirvana more quickly.
<p><b>To mentally translate XPCOM to COM.</b>
<br>&nbsp;
<table BORDER COLS=2 WIDTH="100%" >
<tr>
<td BGCOLOR="#CCCCCC"><b>vanilla COM</b></td>
<td BGCOLOR="#FFCCCC"><b>XPCOM</b></td>
</tr>
<tr>
<td BGCOLOR="#CCCCCC">&nbsp;IUnknown</td>
<td BGCOLOR="#FFCCCC">nsISupports</td>
</tr>
<tr>
<td BGCOLOR="#CCCCCC">IClassFactory</td>
<td BGCOLOR="#FFCCCC">nsIFactory</td>
</tr>
<tr>
<td BGCOLOR="#CCCCCC">virtual void _stdcall</td>
<td BGCOLOR="#FFCCCC">NS_IMETHOD</td>
</tr>
<tr>
<td BGCOLOR="#CCCCCC">interface ID = IID</td>
<td BGCOLOR="#FFCCCC">nsID = nsIID = IID</td>
</tr>
<tr>
<td BGCOLOR="#CCCCCC">class ID = CLSID&nbsp;</td>
<td BGCOLOR="#FFCCCC">nsCID = CID</td>
</tr>
</table>
<p>Not too difficult.
<br>But wait. There's more.
<br><b>-------------------------------------------</b>
<p><b><font size=+1>Why don't those classes have AddRef?</font></b>
<p>Actually, those classes do have AddRef. It is hidden
<br>in a macro. There are alot of&nbsp; macros that are alot of&nbsp; help
<br>once you know :
<br>&nbsp;&nbsp;&nbsp; 1) They exist.
<p>&nbsp;&nbsp;&nbsp; 2) Where they are defined. (They aren't always mnemonic
or onomatipeic.
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
You might want to print them out.)
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mozilla/xpcom/public/nsCom.h
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
mozilla/xpcom/public/nsISupports.h
<p>&nbsp;&nbsp;&nbsp; 3)What they are
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Here's a short list to give you an idea of what you've been missing.
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
The include files listed above are the real reference.
<p>&nbsp;&nbsp;&nbsp; 4) A quick way to expand pesky macros:
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
For macros in&nbsp; foo.cpp,&nbsp; 'make foo.i'
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; This
will pump the foo.cpp file through C preprocessing
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
and expand all the macros for you.&nbsp; The output can be
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
hard to read, but if you search for&nbsp; unique strings
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
in the area you aredebugging, you can navigate
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
the file pretty easily.
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
(thanks to hshaw@netscape.com)
<br>&nbsp;
<br>&nbsp;
<br>&nbsp;
<table BORDER COLS=2 WIDTH="100%" BGCOLOR="#CCCCCC" >
<tr>
<td BGCOLOR="#FFCCCC"><b><font size=+1>Netscape MACRO</font></b></td>
<td><b><font size=+1>Expansion of macro</font></b></td>
</tr>
<tr>
<td BGCOLOR="#FFCCCC">NSADDREF(factoryinstname)</td>
<td>Factory->AddRef();</td>
</tr>
<tr>
<td BGCOLOR="#FFCCCC">NS_IMETHOD</td>
<td>virtual nsresult __stdcall</td>
</tr>
<tr>
<td BGCOLOR="#FFCCCC">NS_INIT_REFCNT()</td>
<td>mRefCnt = 0</td>
</tr>
<tr>
<td BGCOLOR="#FFCCCC">NS_INIT_ISUPPORTS()</td>
<td>NS_INIT_REFCNT()</td>
</tr>
<tr>
<td BGCOLOR="#FFCCCC">NS_DECL_ISUPPORTS</td>
<td>public:
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; NS_IMETHOD QueryInterface(REFNSIID
aIID,
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
void** aInstancePtr);
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; NS_IMETHOD_(nsrefcnt)
AddRef(void);
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; NS_IMETHOD_(nsrefcnt)
Release(void);
<br>&nbsp;&nbsp;&nbsp; protected:
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; nsrefcnt mRefCnt;</td>
</tr>
</table>
<p>&nbsp;<font size=+1>Useful Links to COM Documents:</font>
<p><a href="http://www.mozilla.org/projects/xpcom/">XPCOM&nbsp; Page</a>
<br><a href="http://www.mozilla.org/projects/xpcom/nsCOMPtr.html">nsCOMPtr</a>
<br><a href="http://warp.netscape.com/client/raptor/codingconventions.html">Coding
Conventions</a>
<br><a href="http://warp/client/bam/eng/howto.html">Getting BAMmed</a>
<br><a href="http://warp/client/bam/eng/comdoc.html">How to COM</a>
<br><a href="http://www.mozilla.org/docs/tplist/catFlow/modunote.htm">Modularization
Techniques</a>
<br><a href="http://www.mozilla.org/docs/tplist/catBuild/portable-cpp.html">C++
Portability Guide</a>
<br><a href="http://www.mozilla.org/newlayout/">NGLayout</a>
<br>&nbsp;
<br>&nbsp;
<br>&nbsp;
</body>
</html>