在重新翻阅 < < Creating Applications with Mozilla >> 以及 Alex SirotaLonecat 的帖子后, 总算对 XPCOM 有点入门了… 记录个简单的 C++ component 的例子, 作为以后的参考.

需要的软件: gecko-sdk

1. 建立一个 idl 文件(接口定义)

1
2
3
4
5
6
7
#include "nsISupports.idl"
 
[scriptable, uuid(a765a62c-eb6a-4e4f-a1a8-c66340d3e892)]
interface IMyComponent : nsISupports
{
  long Add(in long a, in long b);
};

其中的 uuid 可由 uuidgen 生成.

2. 使用 xpidl 生成相应的头文件和类型库文件

1
2
xpidl -m header -I_DIR_ IMyComponent.idl
xpidl -m typelib -I_DIR_ IMyComponent.idl

“_DIR_” 替换为gecko-sdk/idl的路径
Read the rest of this entry »

Tags: , ,