Geekout: How to make a C++ XPCOM Component
This is a geek-out side story. Apologies if you’re not a programmer.
Alex Sirota and Mark Finkle have excellent pages on how to make a C/C++ XPCOM component for Windows. However, neither were what I needed: Alex’s didn’t work for Visual Studio Express, and Mark’s wasn’t specific for Firefox. It took me quite a while to get something working, so I thought I should document what worked for me in concrete specific steps:
- If you don’t have it, download Visual C++ Express.
- Download gecko-sdk-win32-msvc-18.104.22.168.zip and extract it to a folder named C:\xulrunner-22.214.171.124
- Download wintools.zip and extract it to C:\temp\wintools
- In the zip file, find these files:
- Copy them to C:\xulrunner-126.96.36.199\gecko-sdk\bin
- Download Mark Finkle’s sample XPCOM visual studio project xpcom-test.zip and extract it into C:\xulrunner-188.8.131.52
- Your folder structure should now look like this (from Mark’s page):
- Open the visual studio project by double clicking on C:\xulrunner-184.108.40.206\xpcom-test\test.sln
- In Visual Studio, select Build->Build Solution. This compiles the code and makes the dll file.
- Open a command window and cd to C:\xulrunner-220.127.116.11\xpcom-test
- run this command> xpidl-build.bat comp.idl
- This will create the xpt file
- Locate these 2 files:
- Copy them to your Firefox components directory at C:\Program Files\Mozilla Firefox\components
- Open a command window and run these commands:
- > C:\xulrunner-18.104.22.168\gecko-sdk\bin\regxpcom.exe -x “C:\Program Files\Mozilla Firefox\components”
- > touch “C:\Program Files\Mozilla Firefox\.autoreg”
- Restart Firefox
- Download this test page to your computer.
- Load the test page in Firefox and click the test button.
- With any luck, you’ll see that 3+4=7. You can now start modifying the component. Be sure to go back and read the pages from Alex Sirota and Mark Finkle for more details.
Hope this saves someone else the trouble someday!
[Updated 2007/11/29 to fix typo and add Firefox Version info]
Firefox version: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:22.214.171.124) Gecko/20071115 Firefox/126.96.36.199
Windows XP SP 2.