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
- Download the Gecko SDK for your platform.
- You can find it at http://ftp.mozilla.org/pub/mozilla.org/mozilla/releases/mozilla1.7/.
- You can choose a different Mozilla release if you like.
- Extract the SDK to a local directory.
- Create a GUID for your main interface.
- On Windows you can use the
guidgen
utility.
- On Linux you can use the
uuidgen
utility.
- Create the interface definition file -
IMyComponent.idl
- Use the following template, add methods and attributes to the interface.
- 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);
};
- 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.
- 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.
- Create your component header file -
MyComponent.h
.
- Start by inserting double inclusion protection code (
#ifndef _MY_COMPONENT_H_ ....
).
- Add
#include "IMyComponent.h"
to include the interface definition.
- Create a GUID for your component.
- 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_
- Copy the header template from
IMyComponent.h
(starting with /* Header file */
) into the MyComponent.h
file.
- Replace all the instances of
_MYCLASS_
with the name of your component.
- Create your component implementation file -
MyComponent.cpp
.
- Add
#include "MyComponent.h"
to include your component definitions.
- Copy the implementation template from
IMyComponent.h
(starting with /* Implementation file */
) into the MyComponent.cpp
file.
- Replace all the instances of
_MYCLASS_
with the name of your component.
- Add method implementation code.
- Create your module definitions file -
MyComponentModule.cpp
.
- Add
#include "nsIGenericFactory.h"
to include Mozilla GenericFactory definitions.
- Add
#include "MyComponent.h"
to include your component definitions.
- Add
NS_GENERIC_FACTORY_CONSTRUCTOR(MyComponent)
to define the constructor for your component.
- 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.
- Add
NS_IMPL_NSGETMODULE("MyComponentsModule", components)
to export the above information to Mozilla.
- 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
- Download the sample code from here.
- Extract the sample to a local directory.
- Edit the makefile.
- The makefile is located in the src directory of the sample.
- It is named
Makefile
for Linux, MyComponent.mak
for Windows
- Edit the makefile, changing the
GECKO_SDK_PATH
variable to point to your Gecko SDK directory.
- Added: When using the included Visual Studio project:
- Open the project settings:
Project > Settings...
- Choose
Settings For: All Configurations
in the upper left corner.
- Open the
C/C++
tab and choose Preprocessor
in the Category
drop-down list.
- Make sure that "Additional include directories" points to your Gecko SDK.
- Open the
Link
tab and choose Input
in the Category
drop-down list.
- Make sure that the "Additional library path" points to your Gecko SDK.
- Build the sample.
- Open a command shell (
cmd
on Windows; tcsh
, bash
, xterm
etc. on Linux).
- Navigate to the sample src directory.
- On Linux issue a
make
command. MyComponent.so
file is created.
- On Windows issue a
nmake /f MyComponent.mak
command. Debug\MyComponent.dll
is created.
- Alternatively, on Windows, issue a
nmake /f "MyComponent.mak" CFG="MyComponent - Win32 Release"
command for a release build. Release\MyComponent.dll
is created.
- Added: When using the included Visual Studio project:
- Select the wanted configuration (Debug/Release) in
Build > Set Active Configuration...
- Choose
Build > Build MyComponent.dll
- Register the new component with Mozilla.
- Copy
MyComponent.so
/MyComponent.dll
and IMyComponent.xpt
file to the Mozilla components directory.
- On Windows this directory is typically located at:
C:\Program Files\Mozilla Firefox\components
.
- On Linux this directory is typically located at
~/firefox/components
(or ~/mozilla/components).
- Run the
regxpcom
command supplied with the Gecko SDK to register the new component.
- You might need to provide an additional parameter:
regxpcom -x _COMPONENTS_DIR_
where _COMPONENTS_DIR_ is the components directory.
- 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.
- 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.
- Test the new component.
- Restart Mozilla.
- Open the
MyComponentTest.html
file provided with the sample and click the "Go" button.
- If everything is OK you should see a dialog saying "3 + 4 = 7".
Links and Resources
Revision History
- June 3, 2005
- Modified the Windows makefile (MyComponent.mak) to work with the latest Gecko SDK. The old version of the sample can be found here.
- Added Visual Studio 6 project file to the sample.
- Added a tip about using the ".autoreg" file for registering new components.
Comments
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
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
great example, great article, and great links. i wish mozilla/mozdev had more simple examples like these. thanks for writing this down alex.
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?
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
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.
Hello, thanks for great sample! Do you know why 'contet-policy' notification does not work under FireFox?
Very clear explanation. However, the sample doesn't build with nmake 1.5 (the free version). :(
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.
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???
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?
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
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?
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!
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 :)
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?
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.
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"?
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.
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.
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.
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.
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
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???
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!
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...
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
really helpful document !!
gr8 job alex.
thanks to kyr0 too.
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
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
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.
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
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?
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.
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 ??
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 ?
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.
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
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
This is great tip to make first xpcom example. =)
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.
works on ff 1.0.2 gecko 1.7 ....no troubles but the classic error on ff 1.5
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.
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.
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
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!
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.
anyone can help me to create a simple app that use XPCOM totally. Especially, how to run this example on Linux
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
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
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.
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!
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);
}
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.
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
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
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!
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!
sorry, sample works with ff1.0.2 and ff1.0.4 but NOT with 1.5+
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?
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
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.
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.
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.
Oh yeah, I also removed the -DXPCOM_GLUE and added -DMOZILLA_STRICT_API.
Works for me (at last). Follow the advice given by kyrO.
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
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
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]
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.
Thanks for your response.
finally, made it to work on firefox 1.5.0.2 and linux.
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
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
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?
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?
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
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 :)
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,
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,
any one tell me . what should i do to create my own component in linux
thanx in advance......
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!
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?
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?
----------
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
----------
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.
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]#
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
has anyone tried to package and deploy the component over the Internet? Any working example like this would be of great help.
Thank you!
http://ehleypnm.com/azqc/cpku.html | http://xthgsbzs.com/nuco/kezr.html
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 !!!
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.
JdDng, did you skip my post? :)
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.
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...)
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.
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 <>
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.
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
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.
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
cehxbfdj qvjgi mzuwbv dljqvn xgjcu lkpxauofe ozcnflbt
oycfthl biwyus vzgeahi stcvlrqe srugnitw zcgjdxeu mlrdp http://www.wfhklrc.fzmolvn.com
oycfthl biwyus vzgeahi stcvlrqe srugnitw zcgjdxeu mlrdp http://www.wfhklrc.fzmolvn.com
oycfthl biwyus vzgeahi stcvlrqe srugnitw zcgjdxeu mlrdp http://www.wfhklrc.fzmolvn.com
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?
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)
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.
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.
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
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
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
are comments closed or something?
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.
iwwB4JWIALaQKK EhxGGe6fl3r pbizpWH1yq
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).
szopjatok le
szopjatok le
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
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????
Components.classes[cid] has no properties
I have looked all topics in this article and nothing help me.
How can I resolve this problem????
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!
I can't wrap this up into an extension. Can anyone send me an example?
My email: pmtyim@yahoo.com
I can't wrap this up into an extension. Can anyone send me an example?
My email: pmtyim@yahoo.com
Comments closed
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