Click here to Skip to main content
13,596,864 members
Click here to Skip to main content
Add your own
alternative version


28 bookmarked
Posted 31 Mar 2009
Licenced CPOL

A simple Firefox Addon with XP-COM Component

, 2 Jul 2010
Rate this:
Please Sign up or sign in to vote.
Beginning a Firefox Addon with the power of XP-COM


Firefox is a nice browser but it becomes really cool and powerful with its Addons. My favorites are Adblock Plus and No Script. For that reason and because I never found such a "complete" sample, I want to deliver a simple sample for extending Firefox. The main focus of the article is the integration of a XP-COM component in a Firefox Addon.

XP-COM means "Cross Platform Component Object Model" and is not COM from Microsoft which is only for Windows, but XP-COM is also for Linux and MAC-OS. For that, please refer here.

For creating the barebone Addon, I used the nice wizard from Ted Mielzarek. It can be found here.


Recently, I was on a Mozilla Addon Workshop and wondered about the questions of writing a Firefox Addon with XP-COM. I remembered how this is done and now I want to share my knowledge and more, my experiences. It isn't a non-trivial task and so it may have some problems. Maybe you got to dig deep to get it to work.

Using the Code

I have included 2 zip files, the first is the code of the XP-COM DLL and the second is the Addon with this DLL and some stuff. The right use is to rename downloaded "zip" as "xpi" so Firefox can install it as Addon. Then you find a button and 2 menu items in "Extras" in the Firefox. They show the implemented interfaces of the DLL and the call of the Explorer shows a system call.

For using the code, you need to install the Gecko-SDK from your machine.

To create the XP-COM code, I used the very powerful and time and energy saving Wizard. It works only in conjunction with the English Version of Visual Studio 2005.

The code worth discussing is in JavaScript:

//Getting the class factory for the class
var compClass = Components.classes[ ";1" ];
//Creating an object with the GUID
var instance = compClass.createInstance();
//asking for that interface
var XpCom = instance.QueryInterface(Components.interfaces.ICodeprojectXPCOM);
//my Call of the object
XpCom.Action(1,"C:\\Program Files");		 

Points of Interest

Writing an Addon is really a pain. In comparison to the Internet Explorer, it looks a little easier. Internet Explorer is more poorly documented and the documents are from the "out of date" Internet Explorer 6.

I learned a lot about XP-COM. It is like revisiting "DLL Hell". If you create DLL with dependencies, it often won't work because firefox.exe runs in its folder and doesn't see other DLLs. That's why I strongly encourage "static linking" and using the Dependency Walker.

Other interesting sources which are used and often consulted are:


  • 31/03/2009 Initial release
  • 02/07/2010 XPI file is now compatible with newer Firefox versions


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Software Developer
Germany Germany
I am living in germany and now living from programming for some Years. In my spare time I like sports as jogging, playing football (soccer) and basketball.

We must take care for our planet, because we and our family has no other. And everybody has to do something for it.

You may also be interested in...

Comments and Discussions

Questionutility and dll Pin
shenbagam1224-Jan-13 21:55
membershenbagam1224-Jan-13 21:55 
AnswerRe: utility and dll Pin
KarstenK8-Jul-13 20:42
memberKarstenK8-Jul-13 20:42 
Questionadd-on Pin
Samar_016-Sep-12 17:55
memberSamar_016-Sep-12 17:55 
AnswerRe: add-on Pin
KarstenK6-Sep-12 21:48
memberKarstenK6-Sep-12 21:48 
QuestionHow to create Menu? Pin
Md. Mazharul Islam Khan1-Jul-10 4:26
memberMd. Mazharul Islam Khan1-Jul-10 4:26 
AnswerRe: How to create Menu? Pin
KarstenK1-Jul-10 4:28
memberKarstenK1-Jul-10 4:28 
GeneralRe: How to create Menu? Pin
Md. Mazharul Islam Khan1-Jul-10 5:12
memberMd. Mazharul Islam Khan1-Jul-10 5:12 
It doesn't support my Firefox version. so, if u tell me which file to be copied where will be best to me for clear concept.

Thanks in Advance
GeneralRe: How to create Menu? Pin
KarstenK1-Jul-10 21:27
memberKarstenK1-Jul-10 21:27 
GeneralRe: How to create Menu? Pin
Md. Mazharul Islam Khan3-Jul-10 19:27
memberMd. Mazharul Islam Khan3-Jul-10 19:27 
GeneralRe: How to create Menu? Pin
KarstenK4-Jul-10 20:57
memberKarstenK4-Jul-10 20:57 
GeneralMy vote of 1 Pin
dxlee6-Oct-09 3:50
memberdxlee6-Oct-09 3:50 
GeneralRe: My vote of 1 Pin
KarstenK10-Nov-09 23:20
memberKarstenK10-Nov-09 23:20 
GeneralMy vote of 1 Pin
Infinitum3D30-Aug-09 1:45
memberInfinitum3D30-Aug-09 1:45 
GeneralRe: My vote of 1 Pin
KarstenK22-Sep-09 22:35
memberKarstenK22-Sep-09 22:35 
GeneralLooking for codes Scrapbook (firefox addon) like utility Pin
RamBi9-Apr-09 1:09
memberRamBi9-Apr-09 1:09 
GeneralRe: Looking for codes Scrapbook (firefox addon) like utility Pin
KarstenK9-Apr-09 1:17
memberKarstenK9-Apr-09 1:17 
QuestionCross platform? Pin
Danila Korablin31-Mar-09 7:49
memberDanila Korablin31-Mar-09 7:49 
AnswerRe: Cross platform? Pin
KarstenK31-Mar-09 21:10
memberKarstenK31-Mar-09 21:10 
GeneralRe: Cross platform? Pin
Danila Korablin31-Mar-09 21:46
memberDanila Korablin31-Mar-09 21:46 
GeneralMy vote of 2 Pin
Jim Crafton31-Mar-09 3:51
memberJim Crafton31-Mar-09 3:51 
GeneralRe: My vote of 2 Pin
KarstenK9-Apr-09 1:25
memberKarstenK9-Apr-09 1:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web03-2016 | 2.8.180621.3 | Last Updated 2 Jul 2010
Article Copyright 2009 by KarstenK
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid