Creating a C++ XPCOM component

About

This is a step-by-step tutorial on creating, building and registering an XPCOM component on Linux and MS Windows.

Download

The complete source code for this tutorial can be downloaded from here.

Creating the component

  1. Download the Gecko SDK for your platform.
    1. You can find it at http://ftp.mozilla.org/pub/mozilla.org/mozilla/releases/mozilla1.7/.
    2. You can choose a different Mozilla release if you like.
    3. Extract the SDK to a local directory.
  2. Create a GUID for your main interface.
    • On Windows you can use the guidgen utility.
    • On Linux you can use the uuidgen utility.
  3. Create the interface definition file - IMyComponent.idl
    1. Use the following template, add methods and attributes to the interface.
    2. Fill in the GUID you have generated.
    	
    #include "nsISupports.idl"
    
    [scriptable, uuid(_YOUR_INTERFACE_GUID_)]
    interface IMyComponent : nsISupports
    {
      long Add(in long a, in long b);
    };
    	
    	
  4. Generate the interface header and typelib files out of the interface definition file.
    • Use the xpidl utility that comes with Gecko SDK.
    • Substitute the "_DIR_" in the following commands with the full path to the xpcom/idl directory found under your Gecko SDK main directory.
    • xpidl -m header -I_DIR_ IMyComponent.idl will create the IMyComponent.h header file.
    • xpidl -m typelib -I_DIR_ IMyComponent.idl will create the IMyComponent.xpt typelib file.
  5. The interface header file IMyComponent.h contains templates for building your component header and implementation files. You can copy and paste the templates to create these files, changing only your component name.
  6. Create your component header file - MyComponent.h.
    1. Start by inserting double inclusion protection code (#ifndef _MY_COMPONENT_H_ ....).
    2. Add #include "IMyComponent.h" to include the interface definition.
    3. Create a GUID for your component.
    4. Add the following lines, which define your component name, contract ID, and GUID:
      
      #define MY_COMPONENT_CONTRACTID "@mydomain.com/XPCOMSample/MyComponent;1"
      #define MY_COMPONENT_CLASSNAME "A Simple XPCOM Sample"
      #define MY_COMPONENT_CID _YOUR_COMPONENT_GUID_ 
      
      
    5. Copy the header template from IMyComponent.h (starting with /* Header file */) into the MyComponent.h file.
    6. Replace all the instances of _MYCLASS_ with the name of your component.
  7. Create your component implementation file - MyComponent.cpp.
    1. Add #include "MyComponent.h" to include your component definitions.
    2. Copy the implementation template from IMyComponent.h (starting with /* Implementation file */) into the MyComponent.cpp file.
    3. Replace all the instances of _MYCLASS_ with the name of your component.
    4. Add method implementation code.
  8. Create your module definitions file - MyComponentModule.cpp.
    1. Add #include "nsIGenericFactory.h" to include Mozilla GenericFactory definitions.
    2. Add #include "MyComponent.h" to include your component definitions.
    3. Add NS_GENERIC_FACTORY_CONSTRUCTOR(MyComponent) to define the constructor for your component.
    4. Add
      
      static nsModuleComponentInfo components[] =
      {
          {
             MY_COMPONENT_CLASSNAME, 
             MY_COMPONENT_CID,
             MY_COMPONENT_CONTRACTID,
             MyComponentConstructor,
          }
      };
      
      
      to define the class name, contract ID and GUID of your component.
    5. Add NS_IMPL_NSGETMODULE("MyComponentsModule", components) to export the above information to Mozilla.
  9. Create the makefiles and/or projects.
    • You can use the templates provided with this sample to create your custom makefile.
    • Alternatively, you can create a Visual C++ project with similar settings (on Windows).

Building the sample

  1. Download the sample code from here.
    • Extract the sample to a local directory.
  2. Edit the makefile.
    1. The makefile is located in the src directory of the sample.
    2. It is named Makefile for Linux, MyComponent.mak for Windows
    3. Edit the makefile, changing the GECKO_SDK_PATH variable to point to your Gecko SDK directory.
    4. Added: When using the included Visual Studio project:
      1. Open the project settings: Project > Settings...
      2. Choose Settings For: All Configurations in the upper left corner.
      3. Open the C/C++ tab and choose Preprocessor in the Category drop-down list.
      4. Make sure that "Additional include directories" points to your Gecko SDK.
      5. Open the Link tab and choose Input in the Category drop-down list.
      6. Make sure that the "Additional library path" points to your Gecko SDK.
  3. Build the sample.
    1. Open a command shell (cmd on Windows; tcsh, bash, xterm etc. on Linux).
    2. Navigate to the sample src directory.
    3. On Linux issue a make command. MyComponent.so file is created.
    4. On Windows issue a nmake /f MyComponent.mak command. Debug\MyComponent.dll is created.
    5. Alternatively, on Windows, issue a nmake /f "MyComponent.mak" CFG="MyComponent - Win32 Release" command for a release build. Release\MyComponent.dll is created.
    6. Added: When using the included Visual Studio project:
      1. Select the wanted configuration (Debug/Release) in Build > Set Active Configuration...
      2. Choose Build > Build MyComponent.dll
  4. Register the new component with Mozilla.
    1. Copy MyComponent.so/MyComponent.dll and IMyComponent.xpt file to the Mozilla components directory.
    2. On Windows this directory is typically located at:
      C:\Program Files\Mozilla Firefox\components.
    3. On Linux this directory is typically located at ~/firefox/components (or ~/mozilla/components).
    4. Run the regxpcom command supplied with the Gecko SDK to register the new component.
    5. You might need to provide an additional parameter:
      regxpcom -x _COMPONENTS_DIR_ where _COMPONENTS_DIR_ is the components directory.
    6. Delete the xpti.dat and compreg.dat files from your Mozilla profile directory.
      These files will be automatically rebuilt by Mozilla the next time it is restarted.
      Added: Alternatively you can "touch" (either create or update) a file called .autoreg in the main Mozilla/Firefox installation directory.
    7. The profile directory is typically located at:
      • ~/.mozilla/firefox/default.??? on Linux.
      • C:\Documents and Settings\USERNAME\Application Data\Mozilla\Firefox\Profiles\default.??? on Windows.
  5. Test the new component.
    1. Restart Mozilla.
    2. Open the MyComponentTest.html file provided with the sample and click the "Go" button.
    3. If everything is OK you should see a dialog saying "3 + 4 = 7".

Links and Resources

Revision History


Get Firefox

FoxyTunes

Comments

Dave wrote:
Hi there,

That really clears things up a good bit regarding XPCOM components!

Just a small question, Ive sucessfully built and registered the component, but when I try to test it out I get a popup window saying:

Type error: Components.classes[cid] has no properties!

Any ideas?

Thanks
Dave
19-Nov-2004 05:44:06

Kevin McAllister wrote:
The link to part 5 of the IBM dw article is broken, the correct link is: http://www-128.ibm.com/developerworks/webservices/library/co-xpcom5.html
01-Dec-2004 22:26:56

Nat Brown wrote:
great example, great article, and great links. i wish mozilla/mozdev had more simple examples like these. thanks for writing this down alex.
21-Dec-2004 17:37:57

Jesse Watson wrote:
Finally got everything to compile and link up, but when I hit the "Go" button, Firefox crashes. I tried to make it an extension instead, packaging the DLL and xpt file inside the components directory (I imitated ColorZilla), but same result... When I call the Javascript function, FireFox always crashes on this line:
obj = Components.classes[cid].createInstance();

Been at this for almost two weeks now and I'm out of ideas... Any thoughts? Is there a tool out there for debugging XPCOM components?
05-Jan-2005 23:21:40

free_zy wrote:
First a huge and great thank you for the "hello world" because the "official" weblock example is really too complex to make it works.

But i think that with the documentation of weblock and this exemple you can make great things

Ok just here is some details/correction :

- an error makes me lost a lot of time :
contrarly against that it is written down the -x option of regxpcom is not the components directory but xcom library directory (from gecko sdk).
So the command line would be something like regxpcom -x C:\gecko-sdk\bin

- you can use a free extention to visualize the components istalled (an interfaces) on you firefox browser. It is downloadabled by clicking here :
http://www.xulfr.org/outils/extensions/cview-0.6.5.xpi

04-Mar-2005 09:57:19

Anand Balaji wrote:
Thanks for the great demo. I was finally able to do something productive. :)

Could you provide me with any information as to how this component could be packaged and deployed via the Internet?

Thanks in advance.
08-Mar-2005 05:50:22

Roman wrote:
Hello, thanks for great sample! Do you know why 'contet-policy' notification does not work under FireFox?
09-Mar-2005 12:38:27

Stan wrote:
Very clear explanation. However, the sample doesn't build with nmake 1.5 (the free version). :(
17-Mar-2005 03:53:34

J wrote:

Hello,

Great example.

The following worked using Firefox 1.02 on Linux.

unzipped the code
regxpcom -x /usr/lib/mozilla-firefox/components
cd ~/.mozilla/firefox/wtwlh2xt.default
rm xpti.dat compreg.dat

reran mozilla with the webpage, hurrah, 7!

Also xpti.dat and compreg.dat recreated as promised.
03-Apr-2005 05:49:00

G.Naudts wrote:
The makefile MyComponent.mak makes reference to files as: $(GECKO_SDK_PATH)\embedstring\bin that are not present in the gecko sdk distribution you mention in your article???
08-Apr-2005 08:25:41

Stan wrote:
I second the comment of G.Naudts. MyComponent.mak references directories in the gecko stdk that just don't exist in the Gecko 1.7 sdk, e.g. embedstring, xpcom. Is this make file meant for a different version of the sdk?
10-Apr-2005 18:52:15

anonymous wrote:
The make file doesn't compile on my system and didn't even find CL.exe and link.exe files. Though I linked it by specifying the path of these files in the make file, but the link flags are not being located by the nmake utility.
Is there any way to link these files automatically
10-May-2005 02:05:07

anonymous wrote:
Thanks for the nice and short article.

To compile/build, I had to also download buildtools.zip from mozilla.

If I define MOZILLA_STRICT_API as suggested by some tutorial, I get a bunch of errors. So, I turn it of for now.

Any idea?
16-May-2005 06:56:00

ragevietnow wrote:
Thanks for the easy example with code that works! I also got this to run under thunderbird for anyone that is interested. You just have to put the .so and .xpt files in the thunderbird/components directory instead and call the javascript function from an overlay in a xul file. simple if you know how to do overlays!
20-May-2005 20:01:16

Santosh Ahuja wrote:
Nice tutorial. Got me started after a week's pondering over the docs at mozilla. I did get the problem Dave was mentioning about ....

Type error: Components.classes[cid] has no properties!

I checked in the profile directory and found that the compreg.dat and xpti.dat were not being created. Also found that 1 or more instances of firefox were running . Closed all instances and started firefox again and it worked.

hmm other problems.. regxpcom always complained about not finding nspr4.dll. So put \program files\Mozilla Firefox in the path and that worked as well.

I used windowsXP and Gecko SDK version 8 the latest. The make files did'nt work for me. So I created a Vc++ project and added the files to compile the dll.All's well now :)
29-May-2005 08:10:16

Diego wrote:
I've tried to compile the source code, but nmake returns a Fatal Error.
I have Visual Studio 6 installed... i need VC 2003 or other c++ compilers, such CYGWIN?
30-May-2005 05:08:26

Santosh Ahuja wrote:
Drop me an email and I can send you the VC 6.0 .dsw project. If that'll help.
Updated by Alex: I've now updated the tutorial and the sample and included a VC 6.0 project file. Thanks.
03-Jun-2005 04:29:01

Ivo Stoyanoff wrote:
Thanks for the update. I had to tweak the library list for link to complete.
Here is my change (in project - settings - link)
... nspr4_s.lib plds4_s.lib plc4_s.lib xpcom.lib xpcomglue.lib
I had some problems with registration - I don't see MyComponent.xpt but IMyComponent.xpt.
I had to add firefox dir to my path for nspr4.dll to be found.
Not sure if that's the correct one - after tweaking/renaming my Firefox started crashing.
I deleted dll/xpt, rerun regxpcom, deleted profile dat files, touched autoreg - no help.
Still crashing...
I am using Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.8) Gecko/20050511 Firefox/1.0.4
and gecko sdk 1.7
Is this some version problem? How to "unregister"?
03-Jun-2005 13:16:22

Alex wrote:
I've updated the tutorial and the sample. The sample now works with the latest Gecko SDK and contains a Visual Studio 6.0 project.
03-Jun-2005 04:17:19

Corina wrote:
Hi,
I followed the example on Windows, the component was registered, but in run-time I get this error that I cannot figure it out.

(NS_ERROR_XPC_CI_RETURNED_FAILURE) [nsIJSCID.CreateInstance]

Any ideas? Thanks.

15-Jun-2005 07:39:36

Corina wrote:
Hi,
I followed the example on Windows, the component was registered, but in run-time I get this error that I cannot figure it out.

(NS_ERROR_XPC_CI_RETURNED_FAILURE) [nsIJSCID.CreateInstance]

Any ideas? Thanks.

15-Jun-2005 07:39:56

pierro81 wrote:
hello,

here pierro (escuse my english i'm french), i want to know how and can you make xpcom component without mozilla, and so develop with only the gecko sdk?

thanks.

22-Jun-2005 04:52:58

Nick wrote:
Joe, I ran into your problem and resolved it by adding xpcom.lib to the list of libraries in Visual Studio. Hope this helps some one
26-Sep-2005 11:03:01

stl wrote:
I've been trying to make your example work for PRFloat64 (double) numbers instead of integers... by changing the last arg type in the Add function... but doesn't work.

Am I missing something???
03-Oct-2005 17:00:52

sky_water wrote:
hi,guys
i compiled and installed but it don't work

Type error: Components.classes[cid] has no properties!

i tried on redhat9.0 with mozilla1.2.1 and redhat 7.3 with mozilla1.3
the same error!
any idea?
thanks!
15-Jul-2005 22:23:59

Tobias Wehrum wrote:
Hi,

I have the same problem as Jesse Watson and Corina. If anyone has an idea what could be the reason, please email me or post it here. Thanks...
28-Jul-2005 12:14:44

Joe wrote:
I tried your example on Windows XP but could not compile properly.

Could you pls advise? Thanks.

Linking...
Creating library .\Release/MyComponent.lib and object .\Release/MyComponent.exp
xpcomglue_s.lib(nsGenericFactory.obj) : error LNK2019: unresolved external symbol __imp__PR_AtomicIncrement referenced in function "public: virtual unsigned long __stdcall nsGenericFactory::AddRef(void)" (?AddRef@nsGenericFactory@@UAGKXZ)
xpcomglue_s.lib(nsGenericFactory.obj) : error LNK2019: unresolved external symbol __imp__PR_AtomicDecrement referenced in function "public: virtual unsigned long __stdcall nsGenericFactory::Release(void)" (?Release@nsGenericFactory@@UAGKXZ)
xpcomglue_s.lib(nsComponentManagerUtils.obj) : error LNK2019: unresolved external symbol _NS_GetComponentManager referenced in function "public: virtual unsigned int __thiscall nsCreateInstanceByCID::operator()(struct nsID const &,void * *)const " (??RnsCreateInstanceByCID@@UBEIABUnsID@@PAPAX@Z)
xpcomglue_s.lib(nsComponentManagerUtils.obj) : error LNK2019: unresolved external symbol _NS_GetServiceManager referenced in function "public: virtual unsigned int __thiscall nsGetServiceByCID::operator()(struct nsID const &,void * *)const " (??RnsGetServiceByCID@@UBEIABUnsID@@PAPAX@Z)
xpcomglue_s.lib(nsMemory.obj) : error LNK2019: unresolved external symbol _NS_RegisterXPCOMExitRoutine referenced in function "class nsIMemory * __cdecl SetupGlobalMemory(void)" (?SetupGlobalMemory@@YAPAVnsIMemory@@XZ)
xpcomglue_s.lib(nsMemory.obj) : error LNK2019: unresolved external symbol _NS_GetMemoryManager referenced in function "class nsIMemory * __cdecl SetupGlobalMemory(void)" (?SetupGlobalMemory@@YAPAVnsIMemory@@XZ)
.\Release/MyComponent.dll : fatal error LNK1120: 6 unresolved externals

04-Sep-2005 04:27:17

Aditya wrote:
really helpful document !!
gr8 job alex.
thanks to kyr0 too.
21-Sep-2005 04:59:38

kyr0 wrote:
If you want to make it runnable in firefox you only have to remove the ~/.mozilla/firefox/components/comreg.dat (Firefox will reconfigure it) and then copy the .so and .xpt to $FIREFOX_PATH/components. Then start the .html with firefox and it will run!

Attention:
I used gecko-sdk from mozilla 1.8 beta1!
There is NO need to register the components with trhe gecko-sdk tool.

Attention2:
copy the gecko-sdk INTO the /src directory of this sample code!
Then run(from src-dir):
gecko-sdk/bin/xpidl -m header IMyComponent.idl

and

gecko-sdk/bin/xpidl -m typelib IMyComponent.idl

this will work!

Attention3:
if the gecko-sdk binarys fails on not founded librarys:

install:
mozilla-dev librarys (under suse linux i.e. mozilla-dev)

Attention4:
Failure: "(NS_ERROR_XPC_CI_RETURNED_FAILURE) [nsIJSCID.CreateInstance]"
you need to copy the generated .xpt file in the firefox-components directory!

Attention5:
Components.classes[cid] has no properties!
The same: you need to copy the generated .xpt file in the firefox-components directory! AND: look for syntax errors in your idl!! the function name MUST be lowercase. (In CPP the function name must be UPPERCASE) -

Attention6:
I will write a better documentation of this all soon on kyr0.org
14-Sep-2005 05:16:28

Christian Wartena wrote:
I tried to compile the example with gcc (from cygwin) under WindowsXP. There was an undefined reference to
NS_NewGenericModule2. Does anyone have an idea what library could provide this function?

/cygdrive/c/DOCUME~1/wartena/LOCALS~1/Temp/ccy5Bdsa.o:MyComponentModule.cpp:(.text+0x68): undefined reference to `NS_NewGenericModule2(nsModuleInfo*, nsIModule**)'
collect2: ld returned 1 exit status
13-Oct-2005 08:50:05

benjamin wrote:
when you get the "Components.classes[cid] has no properties!"-error:

make sure that you have the same versions of the xulrunner and the gecko-sdk, it seams that they don't have to be exactly the same.

using
gecko-sdk-i586-pc-msvc-1.8b1.zip and
xulrunner-1.8b5.en-US.win32.zip works

using
gecko-sdk-i586-pc-msvc-1.8b1.zip and
xulrunner-1.9a1.en-US.win32.zip works not.

took me a hard time to figure that out, the error message is indeed not very helpfull ;(

by the way, does anybody know how i install xpi packages with the xulrunner, it would be nice to have the dom-inspector running for debugging purposes.

by the second way: when i start the xulrunner with
xulrunner application.ini -jsconsole the java-script-console pops up, but in there apear only messages from html-like stuff, not the java-script programming errors that i make in the xul-app.
how do i catch errors that look like this:

<button id="b1" label="Java Script error" oncommand="inexistent_func();"/>

when i run xulrunner with the -console command line arg, the console apears but it stays blanc ;(

thanks in regards and i hope that will help somebody.
10-Mar-2007 16:01:10

Jan Wagner wrote:
Otherwise a nice intro, but, how do you get it to compile in VC++.NET on XP SP2!?

What I've done up till now:

1) installed gecko 1.7 final SDK, updated VStudio project filepath settings => complaints

about lidIDL not being present

2) had to get http://downloads.mozdev.org/www/notes/base.zip for the libIDL and xpidl.exe

bits

3) now the linker can't find nspr4.lib, .dll, etc (not part of gecko 1.7!), had to change

the linker params to nspr4_s.lib etc

4) lot's of unresolved symbols, had to add xpcom.lib and xpcomglue_s.lib to the linker

params

5) now building terminates with the linker errors

xpcomglue_s.lib(nsGenericFactory.obj) : error LNK2019: unresolved external symbol

__imp__PR_AtomicIncrement referenced in function "public: virtual unsigned long __stdcall

nsGenericFactory::AddRef(void)" (?AddRef@nsGenericFactory@@UAGKXZ)
xpcomglue_s.lib(nsGenericFactory.obj) : error LNK2019: unresolved external symbol

__imp__PR_AtomicDecrement referenced in function "public: virtual unsigned long __stdcall

nsGenericFactory::Release(void)" (?Release@nsGenericFactory@@UAGKXZ)
.\Debug/MyComponent.dll : fatal error LNK1120: 2 unresolved externals

So what's up with this, now?
(Makes me wonder how it is possible that a release-version SDK is this self inconsistent and

flawed?)

6) downloaded and installed (overwriting parts of gecko 1.7 sdk) the Netscape Portable

Runtime v4.6 final:
ftp://ftp.mozilla.org/pub/mozilla.org/nspr/releases/v4.6/WINNT5.0_OPT.OBJ/
and renamed all lib*.lib to *.lib, and copied headers to gecko include dir

7) now your XPCOM sample compiles and links fine! The previously generated (xpidl.exe) .xpt

and new .dll placed in firefox\components, plus deleted xpti.dat and compreg.dat.
Sample html file "go" now gives:

(NS_ERROR_XPC_CI_RETURNED_FAILURE) [nsIJSCID.CreateInstance]


Pretty frustrating...

I'd very much appreciate ideas what to do next. Did I maybe go wrong somewhere?



Or, anyone know of some other step-by-step instructions for building a simple xpcom

component, including what all external SDK's and packages you'd have to install on your

system before you can get going?

- Jan
20-Oct-2005 03:37:25

Jan Wagner wrote:
About the above, never mind...

The problem was that offical/final gecko from http://ftp.mozilla.org/pub/mozilla.org/mozilla/releases/mozilla1.7/ did not contain all required files in ./lib!!! On the other hand the final nightly http://ftp.mozilla.org/pub/mozilla.org/mozilla/nightly/latest-1.7/gecko-sdk-i586-pc-msvc.zip contains all necessary libs, and your xpcom sample now works :-)

It might be worth changing the download link under "1. Download the Gecko SDK for your platform." to point to the correct SDK release?
21-Oct-2005 07:58:24

vishesh wrote:
The make file doesn't compile on my system and didn't even find CL.exe and link.exe files. Is there any way to link these files automatically.
08-Nov-2005 21:50:50

Freddie wrote:
Sadly, I get the same exception MSBox...

// Start
Exception... "Component returned failure code: 0x80570015
(NS_ERROR_XPC_CI_RETURNED_FAILURE) [nsIJSCID.createInstance]" nresult: "0x80570015
// END

I have MSVC c++ 2003 / WinXP SP2.
What goes wrong ??
22-Nov-2005 15:04:43

anonymous wrote:
Is there a problem with new versions of Mozilla ? I use Firefox 1.07 and a developer in newsgroup uses FF 1.06. My System is MSVC++ 2003/WinXP, he uses Linux 9.0/ mingw....

Hm... any ideas ?
23-Nov-2005 03:09:43

Dan wrote:

If you planning on deploying your components as an XPI, make sure you build your component DLL in release mode. If you don't, Firefox will (silently) fail to register your component because of missing dependencies on msvcrtd.dll and msvcp60d.dll. It will, of course, work on your machine since you have Visual Studio installed.

It's probably best just to change the project to link with the Multithreaded DLL version of the C runtime even in Debug mode, rather than Debug Multithreaded DLL.

It would be nice if Firefox alerted the user when it fails to load a component's DLL rather than silently ignore the component!

BTW, debugging with Visual Studio 6.0 works great. Just set the exectuable to firefox, set your breakpoints, hit F5, and it works perfectly.
15-Dec-2005 14:47:09

Sabarinathan wrote:
Hai,

To make my component compatible with Firefox 1.5, i tried to compile it against firefox 1.5 Gecko SDK.

I have created a XPCOM Component against Gecko-SDK which was taken from http://ftp.mozilla.org/pub/mozilla.org/mozilla/releases/mozilla1.8b1/gecko-sdk-i686-pc-linux-gnu-1.8b1.tar.gz . I have compiled Successfully .

For Registering the component with Firefox 1.5 , I did the following steps
1. Copied my component .so to firefoxInstallationDirectory/components/
2. Copied my xpt file to firefoxInstallationDirectory/components/
3. Executed touch .autoreg
4.Invoked the firefox

While Invoking firefox i am getting the following error message

./firefox-bin: symbol lookup error: /advent/advent1/srinivasar/firefox/1.5rel/firefox/components/libqecomp_FIREFOX_1.so: undefined symbol: _Z20NS_NewGenericModule2P12nsModuleInfoPP9nsIModule

Please let me know how i can resolve this.


Regards
Sabarinathan.P
02-Jan-2006 00:03:01

anonymous wrote:
I used the same latest gecko (1.8b1) and followed the steps in the description and didn't have any problems running it in Firefox 1.5
04-Jan-2006 11:40:25

noohgnas wrote:
This is great tip to make first xpcom example. =)
05-Jan-2006 05:39:41

omar wrote:
Hi, good tutorial, but i can`t run correctly, the infamous dialog with Components.classes[cid] has no properties showme, may be the people that could run correctly the tutorial, could list the tools that they used ? I try over Firefox 1.5 with Gecko SDK 1.7 running over a Red Hat 9.

Thanks in advance.
12-Jan-2006 14:42:41

anony wrote:
works on ff 1.0.2 gecko 1.7 ....no troubles but the classic error on ff 1.5
23-Jan-2006 07:25:53

anonymous wrote:
Using Mozilla Firefox 1.5 and following the steps it works fine.

Using netscape 7.0 i receive a message box with this error.

// Start
Exception... "Component returned failure code: 0x80570015
(NS_ERROR_XPC_CI_RETURNED_FAILURE) [nsIJSCID.createInstance]" nresult: "0x80570015
// END

Netscape is a gecko based browser so i expected it to work as well. I don't know enough about the differences between netscape and firefox to say why this happens.
23-Jan-2006 10:45:56

anony wrote:
Used Fedora Core,Firefox 1.5---

1. To make it compatible with firefox 1.5, download the latest browser code from mozilla CVS.
http://www.linuxquestions.org/linux/answers/Jeremys_Magazine_Articles/Downloading_Source_Trees_101
(for instructions on using CVS)
2. Build it,latest sdk will appear in /dist/sdk
3. Link against this sdk(edit the Makefile) and follow the instructions in this tutorial
4. All should work now (Didn't work with gecko-sdk 1.8b1 for me)

Good tutorial for first timers.
26-Jan-2006 08:40:25

Marco wrote:
I've got some problems with the regxpcom command. When I try to do it I receive this message: Cannot initialize XPCOM Glue, Can not aquire component registrar, Registration failed: <c1f30001> Firefox\component. What's wrong?!?! please help me
10-Mar-2007 16:00:14

Geraint Edwards wrote:
For Firefox 1.5 there is a VERY EASY way to do the component registration. Just add a components directory to a simple extension, put the dll and xpt files there, close and restart Firefox and it all works (NO MORE STEPS REQUIRED!) :-).

p.s. I couldn't get regxpcom or xpidl to work in Windows XP so use xpidl in linux to generate my header files etc. and was forced to look for an alternative to regxpcom - hence my discovery!
25-Feb-2006 03:51:06

Phan Van Tuan wrote:
I have build your example. But I want to write a client in C++ which use that XPCOM. I have build it with KDevelop but have an error follow when I excute my sample:

error while loading shared libraries: libxpcom.so: cannot open shared object file: No such file or directory

can you help me.
13-Mar-2006 19:21:05

anonymous wrote:
anyone can help me to create a simple app that use XPCOM totally. Especially, how to run this example on Linux
13-Mar-2006 19:24:36

pvtuan wrote:
Anyone can help me to register a new XPCOM Component.

I have use command: regxpcom but appear error:

[asterisk@tuanphan bin]$ regxpcom libxpcom.so
Can not initialize XPCOM Glue
Can not aquire component registrar
Registration failed: (c1f30001) libxpcom.so
[asterisk@tuanphan bin]$ regxpcom .
Can not initialize XPCOM Glue
Can not aquire component registrar
Registration failed: (c1f30001) .

Anyone can help me.

Thanks in advance
pvtuan
15-Mar-2006 03:47:04

alexis sepane wrote:
I tested alex's complete code example.
Fortunately it did compile.

But unfortunately it didn't run.

So I started to figure out WHY NOT. Here we go:

1) I don't know how the registering of the components works in the mozilla suite, but if you are using the firefox branch, you have to decrement the buildID by one day in the compatibility.ini (located in your firefox's user profile directory) BEFORE you start firefox. Only then the compreg.dat file will be rewritten by firefox. Thanks to Nigel McFarlane for this (from hack #82 in O'reilly: Firefox Hacks)!

2) When I finally figured out this point , I could find OTHER XPCOM examples (written in Javascript) being registered in the compreg.dat, but alex's new MyComponent.so/ MyComponent.xpt (I am working on linux) component could NOT be found in compreg.dat.
So there must be something going wrong during registration of alex's example OR c++ components in general (which I don't expect).
So, as some might have guessed: I am getting the error: "Type error: Components.classes[cid] has no properties" (which was discussed several times above, but none of the presented solutions worked (at least for me)).
I tested Firefox 1.0.4 AND 1.5. The same result.

For the other (javascript) examples I have tested (and which have been registered successfully) I though cannot call 'createInstance()'.
Already the call

obj = Components.classes[cid].createInstance()

will leave obj 'undefined' because Components.classes does NOT contain the requested cid (problems with the registration).

Can anyone reproduce the error and/ or give some advice?

Thanx in advance and Successful Coding for you!

alexis
28-Mar-2006 09:56:11

roland wrote:
Has anyone had problems forcing firefox to load the dll? I cannot figure out why some instances of firefox (all v1.5.0.1) work great and others will NOT load the dll (test fails on checking for Components.classes["@mydomain.com/XPCOM..."] which can only mean the dll was never loaded into the firefox process space. I made sure .autoreg is set and that both the dat files are deleted but still no load.
28-Mar-2006 13:00:40

Jay wrote:
I'm having similiar problems trying to load the .so file for Thunderbird 1.5. I'm able to compile this example as well as my own code based on the weblock example. I place my xpt and so file is the components directory (I've tried the main thunderbird components directory as well as my own under extensions). When I start Thunderbird my xpt file gets registered in xpti.dat, but I don't see anything in compreg.dat. Now when I try to use my component I get the "has no properties!" error. I've tried the 1.7 and the 1.8b1 version of the gecko sdk with the same results. Does anyone have any idea where to go from here? Some people have stated that Firefox (or Thunderbird, in my case) fails silently when it can't register a dll/so file. Are there any log files / debug utilities that would should this failure and why it is happening? Thanks for any help!
28-Mar-2006 19:13:26

roland wrote:
For those having the dreaded "cid" problem ... after 3 days of attempting to resolve this I finally found the culprit (although I am not convinced the method doesn't pose risks). The issue is with the dll itself. If firefox decides it can't load the dll, it will NOT load it into compreg.dat (but you should see it in xpti.dat). This was compiled in Windows, so I am not 100% sure what needs to be done for linux distros, however, I changed the run-time library from multithreaded to singlethreaded and everything was fine.

Furthermore, if you wrap this up into an extension, make sure to create an install.js file for that extension and put the dll and xpt into a "Components" directory within the xpi. Firefox will ALWAYS scan the extensions/ext_name/components directories pulling every dll it can. I attached an install template for those of you who care. Hope this helps.

var err = initInstall("_product_name_", "_product_name_", 1.0);
var componentsDir = getFolder("Components");
var chromeDir = getFolder("Chrome");

addFile ("_dll_name_.dll", 1.0,
"_dll_name_.dll", componentsDir, "");

addFile ("_xpt_name_.xpt", "1.0",
"_xpt_name_.xpt", componentsDir, "");

err = addDirectory ("_directory_name_", "1.0",
"", chromeDir, "")

if (err==SUCCESS)
performInstall();
else
{
cancelInstall(err);
alert(err);
}
30-Mar-2006 15:19:29

roland wrote:
I forgot to add that developer.mozilla.org specifies to build as multi-threaded in big bold letters, then proceeds to say "(this needs clarification)". So I am not sure of the ramifications.
30-Mar-2006 15:43:54

EKenDo wrote:
anyone getting the following after doing a "release" build from the javascript:

(NS_ERROR_XPC_CI_RETURNED_FAILURE) [nsIJSCID.CreateInstance]

should see Jan's post about a funky gecko SDK. THANX JAN, saved me crazy time. The example works for me under XP, ff 1.5 using this SDK
http://ftp.mozilla.org/pub/mozilla.org/mozilla/nightly/latest-1.7/gecko-sdk-i586-pc-msvc.zip
04-May-2006 08:16:48

tom wrote:
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
This example is just NOT WORKING!!!

As everyone can see: the comments list with unanswered questions is much longer than the instructions of the example.
It seems, that Alex Sirota is too busy with his job as that he could correct the example to a working version.
I guess everybody who IS expecting an example is expecting a WORKING example on a webpage, but this site unfortunately could NOT serve this!

There are several people (including me) who tried to make the example work for several days.

Alex: please remove this example because more people will WASTE TIME with a broken example OR fix it to a working version!
Anything else would be UNFAIR!

I agree with the first comment, that the world needs such a compact tutorial on XPCOM components, but it needs a working one! When it is going to work, it will definately be a greet help for many programmers!

Until then: Everybody is hereby given advice to try the example (to have the chance to learn s.th. or use the chance, that it works on your system, but if you get the error

Type error: Components.classes[cid] has no properties!

do stop working IMMEDIATELY. This example then REALLY DOES NOT WORK on your system (as on many if not all other systems)!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

FYI: I for myself tested on Linux, Firefox versions 1.0.4, 1.5rc1, 1.5 and 1.5.0.1. None worked!

Let the internet be a fair place!
Only then can it stay valuable for each one of us!
03-Apr-2006 17:02:11

tom wrote:
After yet another long coding night I found out, that the sample works with firefox 1.0.2 but not with 1.0.4 and above. So, what is going wrong there? Are there these big changes in firefox?? I can't believe it!
03-Apr-2006 21:21:36

tom wrote:
sorry, sample works with ff1.0.2 and ff1.0.4 but NOT with 1.5+
03-Apr-2006 21:41:42

Boris wrote:
Thanks for the sample, it works great for me with ff 1.5.0.1, WinXP and compiled with Visual C++. Does anyone now how to deploy automatically such a librarie on a client browser when he access a webpage?
04-Apr-2006 13:39:05

alexis sepane wrote:
Hi,

so it seems the example is working for firefox 1.5 on windows but not on linux. Something is going wrong with component registration there?! The new component shows up in my xpti.dat file but not in compreg.dat. I tried nearly any registration method I found on the web. I thought it should be so easy...

Greetings,
alexis
06-Apr-2006 11:56:24

huazilin wrote:
I cann't regxpcom successfully.But it also works for firefox 1.5.0.1 on windows compiled with VC6,I don't why.Does it not necessarily registered.Please give some reply.
06-Apr-2006 17:49:30

anonymous wrote:
09-Apr-2006 03:58:45

Cool_dude wrote:
Cant able to register XPCOM component on linux. The insterfac is visible in xpti.dat but the component is not getting displayed in compreg.dat. The component is not getting loaded when firefox starts up.

Can anyone help me out.

Thanks in advance.
09-Apr-2006 04:07:00

Todd wrote:
On Linux I changed the makefile to link in libxpcom.so and libxpcom_s.a based on the information at; http://developer.mozilla.org/en/docs/XPCOM_Glue#Using_Frozen_linkage_.28dependent_on_xpcom.dll.29

GECKO_LDFLAGS = -L $(GECKO_SDK_PATH)/lib \
-lxpcom \
-lnspr4 \
-lplds4

I also changed the link order, which is apparently VERY important on Linux;

$(FILES) $(GECKO_SDK_PATH)/lib/libxpcomglue_s.a $(GECKO_LDFLAGS)

This will cause NS_NewGenericModule2 to be defined, rather than undefined.

12-Apr-2006 10:34:42

Todd wrote:
Oh yeah, I also removed the -DXPCOM_GLUE and added -DMOZILLA_STRICT_API.
12-Apr-2006 10:37:04

Jibril wrote:
Works for me (at last). Follow the advice given by kyrO.
13-Apr-2006 00:31:02

cool_dude wrote:
After changing the make file also, I am not able to register the component in linux. I tried using both gecko-sdk 1.7 and 1.8. But no luck so far. Is there any version dependency of firefox on gecko-sdk.

Can anyone successful on registring the sample on linux please post their make file?

Thanks in advamnce
17-Apr-2006 00:56:39

anonymous wrote:
DId you change the order of files? I think that one is the most important one:

remove -lxpcomglue from GECKO_LDFLAGS

put $(FILE) and libxpcomglue_s.a in front of GECKO_LDFLAGS
19-Apr-2006 18:07:57

anonymous wrote:
Makefile:

[code]
CXX = c++
CPPFLAGS += -fno-rtti \
-fno-exceptions \
-shared

# Change this to point at your Gecko SDK directory.
GECKO_SDK_PATH = /home/username/gecko-sdk

# GCC only define which allows us to not have to #include mozilla-config
# in every .cpp file. If your not using GCC remove this line and add
# #include "mozilla-config.h" to each of your .cpp files.
GECKO_CONFIG_INCLUDE = -include mozilla-config.h

GECKO_DEFINES = -DXPCOM_GLUE

GECKO_INCLUDES = -I $(GECKO_SDK_PATH)/include

GECKO_LDFLAGS = -L $(GECKO_SDK_PATH)/lib \
-lnspr4 \
-lplds4

FILES = MyComponent.cpp MyComponentModule.cpp

TARGET = MyComponent.so

build:
$(CXX) -Wall -Os -o $(TARGET) $(GECKO_CONFIG_INCLUDE) $(GECKO_DEFINES) $(GECKO_INCLUDES) $(FILES) $(GECKO_SDK_PATH)/lib/libxpcomglue_s.a $(GECKO_LDFLAGS) $(CPPFLAGS) $(CXXFLAGS)
chmod +x $(TARGET)
strip $(TARGET)

clean:
rm $(TARGET)
[/code]
19-Apr-2006 18:51:43

Andrea wrote:
Finally, made it work on Firefox 1.5.0.3 and linux.
I was getting the "Components.classes[cid] has no properties" error.
To make it work, don't use gecko-sdk 1.8.
Download mozilla source and build it.
ftp://ftp.mozilla.org/pub/mozilla.org/firefox/releases/1.5.0.3/source/
To build follow instructions here:
http://developer.mozilla.org/en/docs/Build_and_Install
Then in the directory: /mozilla/obj-i686-pc-linux-gnu/dist/sdk,
you will find the same tools, libs and headers that are in gecko-sdk 1.8.
Link your xpcom component against the libs that you just compiled and it will work.
Today date: 08 May 2006.
08-May-2006 03:03:01

Cool_dude wrote:
Thanks for your response.
finally, made it to work on firefox 1.5.0.2 and linux.
08-May-2006 07:03:03

girish wrote:
Hi, I am developing an extension for firefox 1.5+ (for both windows and linux OS). I developed an C++ XPCOM component with Gecko SDK 1.7 and it worked fine (on windows), when I build the same component with Gecko SDK 1.8a1 it doesn't work.
Can anyone tell me what could be the problem?? Also me suggest the best version of Gecko-sdk (with all the libs,idl and header files) that suits my requirement and also where from where I can download (since many versions are available).

Thanks in Adavance
11-May-2006 01:01:31

Andrea wrote:
I have no idea about Windows.
On Linux with Firefox 1.5.0.* i tried different versions of Gecko-sdk but non worked for me.
So i downloaded mozilla source, build it, and linked with the (gecko) sdk found in:
/where-you-downloaded/mozilla/obj-i686-pc-linux-gnu/dist/sdk

11-May-2006
11-May-2006 08:05:22

girish wrote:
The component which was built with gecko-sdk 1.7 works on both linux and windows (firefox 1.5.0.2). But when I tried the ame component with gecko-sdk 1.8a1 it fails to register (entry is not appeared in compreg.dat but appears in xpti.dat) on windows. I haven't tried it on linux.

can anyone tell me what could be the problem with 1.8a1 version of gecko-sdk?
11-May-2006 09:07:32

sciascid wrote:
hi guys, my problem is that i can't compile using the provided makefile. i always get the following error:
c++ -Os -o MyComponent.so -DMOZILLA_STRICT_API -I../../mozilla/dist/sdk/include -fno-rtti -fno-exceptions MyComponent.cpp MyComponentModule.cpp ../../mozilla/dist/sdk/lib/libxpcomglue_s.a -L../../mozilla/dist/sdk/lib -lxpcom -lnspr4 -lplds4
/usr/bin/ld: warning can't open dynamic library: @executable_path/libxpcom_core.dylib referenced from: ../../mozilla/dist/sdk/lib/libxpcom.dylib (checking for undefined symbols may be affected) (No such file or directory, errno = 2) .... (long list of undefined things)
i can't figure out what's happening! some ideas?
31-Aug-2006 17:28:08

varmag wrote:
Hi all,

I working on a XPCOM development. I am able to build a XPCOM component on Windows and I am able to access the component through Java script. Can any body tell how to build XPCOM components on Mac OSX. I tried to build the component as per the steps given for linux. I am able to create the component but I am unable to call it from Java Script. When I tried to explore the component through XPCOM component viewer , no iterfaces are getting displayed. i am thinking that it may be aproblem with make file. I am new to Mac environment. Please guide me how to proceed, If possible please send me sample make file on Mac.
Thanks and Regards
Varmag
31-Aug-2006 04:17:34

Sarjeet Singh wrote:
Hi,
I tried to create a sample XPCOM component through Visual C++ SDK.
I encountered an error while compiling the
the project:
"error MIDL2025 : syntax error : expecting an interface name or DispatchInterfaceName or CoclassName or ModuleName or a COM object name or LibraryName or a type specification near "%" "
This error is pointing to nsrootidl.idl(44) file.
Can anybody help me out please? I am new
to XPCOM :)
20-Jul-2006 07:15:28

cool_dude wrote:
Hi All,
Can anyone help me in building mozilla from source on windows XP. If someone already done it please post the steps to built it.

Thanks in advance,
23-Aug-2006 03:51:25

anonymous wrote:
Hi All,
Can anyone help me in building mozilla from source on windows XP. If someone already done it please post the steps to built it.

Thanks in advance,
23-Aug-2006 03:50:49

balaji patil wrote:
any one tell me . what should i do to create my own component in linux
thanx in advance......
22-Jun-2006 02:10:18

Andrew wrote:
For all of you out there who are having problems with the sample not registering with Firefox (one of the symptoms is the infamous "Type error: Components.classes[cid] has no properties!"), be informed that after several days of three people trying to build and install the extension with VS 2005, we reverted back to VS 6.0 with the required service packs (see: http://developer.mozilla.org/en/docs/Windows_Build_Prerequisites_on_the_1.7_and_1.8_Branches#Compiler_.26_Linker) and things magically started working! So, as luck would have it, you must use just the right version of development tools and libraries to get things to work.

So here's what you need: gecko-sdk-1.7.13 and VS 6.0 with sp5.

Good luck!
18-Aug-2006 13:40:03

anonymous wrote:
Just a small question, Ive sucessfully built and registered the component, but when I try to test it out I get a popup window saying:

Type error: Components.classes[cid] has no properties!

Any ideas?
21-Jun-2006 16:23:44

anonymous wrote:
Just a small question, Ive sucessfully built and registered the component, but when I try to test it out I get a popup window saying:

Type error: Components.classes[cid] has no properties!

Any ideas?
21-Jun-2006 16:24:05

Adi KR wrote:
----------

I want to update my last post.

1.-I have solved my first error "OK" Solution:
I used to using components like this:
#define MY_COMPONENT_CONTRACTID "ITTS/itts"
I change the above to:
#define MY_COMPONENT_CONTRACTID "@ITTS.com/itts"
And made change in extension usage, and my first error is solved.

2.-Second error not solved yet: Where does the Mozilla search for components. Maybe my .dll path locating B.TTS is miss.

B.TTS is supposed to be searched in the same directory (APPLICATION DIR) with my .dll. I have put it all in the components directory. But Mozilla still asking this file.

- My E-mail: adikr@telkom.net.
- Posted: 20-June-2006

----------
20-Jun-2006 06:32:48

Adi KR wrote:
First of all, thanks for the tutorial. It can make mozilla reads my component.

-------------------------I Want to ask questions:

I got these following error after trying this example on Mozilla Firefox 1.5 and using nightly-build sdk 1.7.

1.-First Error:

[Exception⦠âComponent returned failure code: 0x80570015
(NS_ERROR_XPC_CI_RETURNED_FAILURE)[nsIJSCID.createInstance]â nsresult: â0x80570015
(NS_ERROR_XPC_CI_RETURNED_FAILURE)â location: âJS frame :: chrome://indotts/content/wordcapture

This Error occurs every after open and close after running my .xpi. (Only first installation succeeds âthe component recognized).
(I have done the above instruction and add a .js to add to components directory):

-------------
var err = initInstall("IndoTTS", "indotts", 1.0);

addFile("MyComponent.dll", "1.0" , "MyComponent.dll", componentsDir, "")
addFile("IMyComponent.idl", "1.0" , "IMyComponent.idl", componentsDir, "")
addFile("A.tts", "1.0" , "A.tts", componentsDir, "")
addFile("B.tts", "1.0" , "B.tts", componentsDir, "")
addFile("C.tts", "1.0" , "C.tts", componentsDir, "")
addFile("ITTS_DLL.dll", "1.0" , "C.tts", componentsDir, "")

var componentsDir = getFolder("Components");
var cf = getFolder("Chrome");
err = addDirectory ("indotts", "1.0",
"", chromeDir, "")

if (err==SUCCESS) {
performInstall();
alert(err);
}
else {
cancelInstall(err);
alert(err);
}
-------------
( I have even tried to copy all of the file to \Program Files\Mozilla Firefox\Plugins and Components Directory)

-Summary of What I Want To Ask:
How to register a component âforeverâ in Mozilla.

-My Current Solution:
Delete the compreg.dat and xpti.dat everytime the Mozilla closed.

-My âOKâ Solution:
Not Yet Known.

2.-Second Error: (after the component is ready)

Error: File B.TTS does not exist. (Mozilla doesnât know where this file, which my dll needs, although I already have it copied to:
\Application Data\Mozilla\Firefox\Profiles\y19u8p4v.default\extensions\indotts@indotts\components\)

( I have also copy all of the file to \Program Files\Mozilla Firefox\Plugins and Components Directory)

-Summary of What I Want To Ask:
Where does the Mozilla search for all components.

-My Current Solution:
None.

-------------------------Thanks all for the solution.
20-Jun-2006 05:35:58

anonymous wrote:
While i am registering new component on linux folowing error occur what will be screw in that

[root@l13-46 mozilla-1.7.12]# /usr/gecko-sdk/bin/regxpcom 'x- /usr/lib/mozilla-1.7.2/components'
Can not initialize XPCOM Glue
Can not aquire component registrar
Registration failed: (c1f30001) x- /usr/lib/mozilla-1.7.2/components
[root@l13-46 mozilla-1.7.12]#
10-Sep-2006 23:07:48

Abhishek Kohli wrote:
The sample is working on Linux 2.6.15-23-386. I was getting the same error as many others-
Type error: Components.classes[cid] has no properties!

I am using Firefox 1.5.0.3. I found out that i was using the wrong gecko-sdk version(Gecko 1.7). i downloaded the correct version, that is Gecko 1.8, and it worked!

The link to download Gecko 1.8 is
http://developer.mozilla.org/en/docs/Gecko_SDK
13-Sep-2006 12:01:54

Abhishek Kohli wrote:
has anyone tried to package and deploy the component over the Internet? Any working example like this would be of great help.
20-Sep-2006 15:03:17

Colin wrote:
Thank you!
http://ehleypnm.com/azqc/cpku.html | http://xthgsbzs.com/nuco/kezr.html
21-Sep-2006 01:36:18

JDong wrote:
Originally, I tried the author's code on
Red Hat AS 4 and Firefox 1.5.0.3. and gecko-sdk 1.7. It failed and show error message: Components.classes[cid] has no properties.

Then I follow the suggestion from Andrea
I include his suggestion below "

Download mozilla source and build it.
ftp://ftp.mozilla.org/pub/mozilla.org/firefox/releases/1.5.0.3/source/
To build follow instructions here:
http://developer.mozilla.org/en/docs/Build_and_Install
Then in the directory: /mozilla/obj-i686-pc-linux-gnu/dist/sdk,
"
When you compile the author's code, you need to change the Makefile and link the library in mozilla/obj-i686-pc-linux-gnu/dist/sdk,
"

It works !!!

27-Sep-2006 18:44:36

JDong wrote:
Finally I figure out the cause of this error message "

Components.classes[cid] has no properties."

The reason is that the wrong gecko-sdk is used. If you use firefox 1.5 or above, you have to use Gecko-SDK 1.8. This is why the author's sample works when you use Gecko-sdk 1.8 or SDK compiled from mozilla source.
27-Sep-2006 19:05:49

Abhishek kohli wrote:
JdDng, did you skip my post? :)
29-Sep-2006 11:49:00

George Akpoly wrote:
any idea regarding the error below:

Creating library Debug/MyComponent.lib and object Debug/MyComponent.exp
MyComponentModule.obj : error LNK2001: unresolved external symbol "unsigned int __cdecl NS_NewGenericModule2(struct nsModuleInfo const *,class nsIModule * *)" (?NS_NewGenericModule2@@YAIPBUnsModuleInfo@@PAPAVnsIModule@@@Z)
Debug/MyComponent.dll : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
09-Oct-2006 16:45:57

Farkbert wrote:
George, I had the same error. I think the problem is that the version of the gecko-sdk you are using is different than the one that works with the authors example (I used the gecko-sdk for xulrunner 1.8.0.4 and had the same exact problem). You need to change the link line a bit to make it work:

For example, change the definition of link32_flags = (...a bunch of windows libs...) xpcomglue.lib (...a bunch more stuff)

to the following:

link32_flags = (...a bunch of windows libs...) xpcom.lib xpcomglue_s.lib (...a bunch more stuff)

...that worked for me. Don't forget that link32_flags is defined twice in the makefile...once for each of the Debug and Release versions. You should change both.

Hope that helps.

(Now of course..If I could get my own component to register with XULRunner that would just make my night...)

10-Oct-2006 15:03:55

Sam Lie wrote:
for those of you who keep getting the
'components.classes[cid] has no properties' problem. i had an xpcom that
was working on mozilla 1.7 then moved to firefox 1.5 and had this problem.
basically firefox really expected the xpcom to be in the directory 'components'.
so if you dont put your component in that directory the browser never found nor registered your component.

[REMOVED XML CODE]


notice i added prefix="components" for the component line.

hope that helps.
10-Mar-2007 16:00:14

anonymous wrote:
my ant build.xml script which specifies the component to be in the 'components' directory :

{?xml version="1.0"?}
{project name="MYXP" default="createxpi"}
{target name="createjar"}
{zip destfile="myxp.jar" basedir="."
includes="content/**" /}
{/target}
{target name="createxpi" depends="createjar"}
{zip destfile="c:\myxp\myxp.xpi"}
{zipfileset dir="." includes="SAT.jar"
prefix="chrome" /}
{zipfileset dir="." includes="myxp.dll" prefix="components" /}
{zipfileset dir="." includes="imyxp.xpt" prefix="components" /}
{zipfileset dir="." includes="install.rdf" /}
{zipfileset dir="." includes="install.js" /}
{/zip}
{/target}
{/project}



note : replace {} with <>
10-Mar-2007 16:00:14

anonymous wrote:
the solution 'put your components' in the components directory has alreeady been mentioned few times already.. except somehow the message wasn't explicit enough.. so yeah put the bloody components in a sub-directory called components or you will get the
'components.classes[cid] has no properties' freaken error.
12-Oct-2006 03:30:14

Sam Lie wrote:
another major problem that i encountered
was XPCOM linking issues, my previous
xpcom on Mozilla 1.7 used the following
libraries :

nspr4.lib plds4.lib plc4.lib xpcomglue.lib

and everything was fine. when i moved to firefox i started having linking problems until i changed the libraries to :

nspr4.lib plds4.lib plc4.lib xpcom.lib xpcomglue_s.lib

(removed xpcomglue_s.lib and added xpcom.lib and xpcomglue_s.lib)

and now no link problems.

this msg from moz developer here helped.
http://www.mail-archive.com/mozilla-xpcom@mozilla.org/msg05096.html


12-Oct-2006 05:23:27

Farkbert wrote:
I just want to add an update. I was originally using VC8 (2005 .NET Express) to build my component and it would not register with XULRunner 1.8.0.4 or with FF1.5. After a whole wasted day of trying, I finally scrounged up a copy of VC7.1 and now everything works.

I'd say, if you want to use VC8 to build your component, you'll have to get a build of your run-time environment built with VC8 in order to get everything working. Since the older builds (the 1.8.0 branch, FF1.5) won't build with VC8....you may be forced to work with a newer version.
18-Oct-2006 08:36:15

abhishek kohli wrote:
i have a working xpcom component on windows XP. what i want to do is add a value to the PATH variable in windows through my component. i know i have to instantiate nsIEnvironment and use the "Set" method. But i don't know where to get started about that. Any ideas?

thanks
26-Oct-2006 11:48:06

iunx frblki wrote:
cehxbfdj qvjgi mzuwbv dljqvn xgjcu lkpxauofe ozcnflbt
11-Feb-2007 12:20:17

cysl mhor wrote:
oycfthl biwyus vzgeahi stcvlrqe srugnitw zcgjdxeu mlrdp http://www.wfhklrc.fzmolvn.com
11-Feb-2007 12:20:25

cysl mhor wrote:
oycfthl biwyus vzgeahi stcvlrqe srugnitw zcgjdxeu mlrdp http://www.wfhklrc.fzmolvn.com
11-Feb-2007 12:20:26

cysl mhor wrote:
oycfthl biwyus vzgeahi stcvlrqe srugnitw zcgjdxeu mlrdp http://www.wfhklrc.fzmolvn.com
11-Feb-2007 12:21:27

Mike wrote:
Hmm, I can't get it to compile either. I get this output:

Microsoft (R) Program Maintenance Utility Version 8.00.50727.42
Copyright (C) Microsoft Corporation. All rights reserved.

No configuration specified. Defaulting to MyComponent - Win32 Debug.
cl.exe /nologo /MDd /W3 /Gm /ZI /Od /I "C:\gecko-sdk\include" /FI"C:\ge
cko-sdk\include\mozilla-config.h" /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D "_MBCS
" /D "_USRDLL" /D "XPCOM_GLUE" /FR".\Debug\\" /Fp".\Debug\MyComponent.pch" /YX /
Fo".\Debug\\" /Fd".\Debug\\" /FD /GZ /c .\MyComponent.cpp
NMAKE : fatal error U1077: '"C:\Program Files\Microsoft Visual Studio 8\VC\bin\c
l.exe"' : return code '0xc0000135'
Stop.

Anybody have any suggestions as to what I'm doin wrong?
04-Nov-2006 10:31:20

Peous wrote:
Under Windows (Visual 2005), FireFox2.0

- Use SDK 1.7.13
http://releases.mozilla.org/pub/mozilla.org/mozilla/releases/mozilla1.7.13/gecko-sdk-i586-pc-msvc-1.7.13.zip

- Listen to Free_Zy: an error makes me lost a lot of time : contrarly against that it is written down the -x option of regxpcom is not the components directory but xcom library directory (from gecko sdk).
So the command line would be something like regxpcom -x C:\gecko-sdk\bin

Here you are !
(It works for me)
13-Nov-2006 09:17:29

Garrett wrote:
On Linux (mine is Fedora Core 6) with SELinux enabled, my /var/log/audit/audit.log was showing:
avc: denied { execmod } for pid=4645
comm="firefox-bin" name="MyComponent.so" dev=dm-0 ino=8941119 scontext=user_u:sy
stem_r:unconfined_t:s0 tcontext=user_u:object_r:lib_t:s0 tclass=file

So, I did chcon system_u:object_r:textrel_shlib_t MyComponent.so .


That, along with many of the other tips here got me up and running successfully.

Thanks for this tutorial. I really like the minimal approach to get started with.

16-Nov-2006 08:28:44

Dave Kok wrote:
If anyone is having problems, eg getting unresolved references than check this webpage http://developer.mozilla.org/en/docs/XPCOM_Glue.
Look up dependent glue in the table and use the settings there. Make sure you don't have XPCOM_GLUE defined in your makefile like in the above example. This is only for standalone glue which properly not what you want. Also in the example mozilla-config.h is included in the makefile. Change this to xpcom-config.h as stated on the webpage.
24-Mar-2007 04:21:35

Gouchi wrote:

Some feedback :

Firefox
Mozilla/5.0 (X11; U; Linux i686; fr; rv:1.8.1.2) Gecko/20060601
Firefox/2.0.0.2)

Gecko SDK
gecko-sdk-i686-pc-linux-gnu-1.8.0.4.tar.bz2 OK without change
gecko-sdk-i686-pc-linux-gnu-gtk2+xft-1.8b1.tar.gz KO with/out change
28-Mar-2007 12:32:23

Dan wrote:
How to *really* get the sample working on
WinXP SP2 VS2005, gecko 1.7
---------------------------------------

1. Download and extract the sample:
http://www.iosart.com/firefox/xpcom/xpcom-sample.zip

2. Download and extract this 1.7 nightly sdk:
http://ftp.mozilla.org/pub/mozilla.org/mozilla/nightly/latest-1.7/gecko-sdk-i586-pc-msvc.zip

3. Open sample project in VS2005 and make the following modifications.
Add the sdk \include to C++-General-Additional Include Directories
Add the sdk \lib to Linker-General-Additional Library Directories
Add xpcomglue_s.lib to Linker-Input_Additional Dependencies

4. Build project in Release configuration and copy resulting src\Release\MyComponent.dll and src\IMyComponent.xpt to c:\Program Files\Mozilla Firefox\components

5. Open and resave file c:\Program Files\Mozilla Firefox\.autoreg

6. Restart firefox and open MyComponentTest.html

-dan
23-Mar-2007 05:25:01

Dan wrote:
How to *really* get the sample working on
WinXP SP2 VS2005, gecko 1.7
---------------------------------------

1. Download and extract the sample:
http://www.iosart.com/firefox/xpcom/xpcom-sample.zip

2. Download and extract this 1.7 nightly sdk:
http://ftp.mozilla.org/pub/mozilla.org/mozilla/nightly/latest-1.7/gecko-sdk-i586-pc-msvc.zip

3. Open sample project in VS2005 and make the following modifications.
Add the sdk \include to C++-General-Additional Include Directories
Add the sdk \lib to Linker-General-Additional Library Directories
Add xpcomglue_s.lib to Linker-Input_Additional Dependencies

4. Build project in Release configuration and copy resulting src\Release\MyComponent.dll and src\IMyComponent.xpt to c:\Program Files\Mozilla Firefox\components

5. Open and resave file c:\Program Files\Mozilla Firefox\.autoreg

6. Restart firefox and open MyComponentTest.html

-dan
23-Mar-2007 05:27:16

test wrote:
are comments closed or something?
23-Mar-2007 05:27:58

ajay wrote:
can anyone tell me build firefox source on RedhatLinux9.0 with Gcc3.2.2 .or send me .mozconfig file , so that i can cross check that file.
13-Mar-2007 01:45:00

M7OT2Ft0Tl wrote:
iwwB4JWIALaQKK EhxGGe6fl3r pbizpWH1yq
23-Nov-2006 08:04:05

Ian Malone wrote:
AFAICT "Components.classes[cid] has no properties!" will turn up whenever the component wasn't added.
On Fedora Core (FC5), I had to shuffle the Makefile so $(GECKO_LDFLAGS) came after everything else (otherwise the stuff in xpcomglue isn't linked).
23-Nov-2006 14:52:56

sandor cristian wrote:
szopjatok le
07-Dec-2006 07:06:13

sandor cristian wrote:
szopjatok le
07-Dec-2006 07:06:26

Tomekk wrote:
Sam Lie can you tell me where you find out that for thunderbird it is neede to change the lib´s.

Now It works
thx Sam Lie
14-Dec-2006 07:45:41

Man From Russia wrote:
Can not initialize XPCOM Glue
Can not aquire component registrar
Registration failed: (c1f30001) and
Can not initialize XPCOM Glue
Can not aquire component registrar
Registration failed: (c1f30001) Settings\User\My
Can not initialize XPCOM Glue
Can not aquire component registrar

How can I resolve this problem????
27-Dec-2006 01:28:39

Dev wrote:
Components.classes[cid] has no properties

I have looked all topics in this article and nothing help me.
How can I resolve this problem????
27-Dec-2006 06:17:18

Dev wrote:
After three days attepmted IT'S WORKS!
I have WinXP SP2, VS2005, ff1.5 & 2.0, gecko 1.8 from http://developer.mozilla.org/en/docs/Gecko_SDK
base from
http://downloads.mozdev.org/www/notes/base.zip
It works fine!
28-Dec-2006 00:28:20

PMT wrote:
I can't wrap this up into an extension. Can anyone send me an example?
My email: pmtyim@yahoo.com
01-Jan-2007 01:23:16

PMT wrote:
I can't wrap this up into an extension. Can anyone send me an example?
My email: pmtyim@yahoo.com
01-Jan-2007 01:23:21
Comments closed