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
guidgenutility. - On Linux you can use the
uuidgenutility.
- On Windows you can use the
- 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/idldirectory found under your Gecko SDK main directory. xpidl -m header -I_DIR_ IMyComponent.idlwill create theIMyComponent.hheader file.xpidl -m typelib -I_DIR_ IMyComponent.idlwill create theIMyComponent.xpttypelib file.
- The interface header file
IMyComponent.hcontains 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 theMyComponent.hfile. - Replace all the instances of
_MYCLASS_with the name of your component.
- Start by inserting double inclusion protection code (
- 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 theMyComponent.cppfile. - Replace all the instances of
_MYCLASS_with the name of your component. - Add method implementation code.
- Add
- 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
to define the class name, contract ID and GUID of your component.static nsModuleComponentInfo components[] = { { MY_COMPONENT_CLASSNAME, MY_COMPONENT_CID, MY_COMPONENT_CONTRACTID, MyComponentConstructor, } }; - Add
NS_IMPL_NSGETMODULE("MyComponentsModule", components)to export the above information to Mozilla.
- Add
- 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
Makefilefor Linux,MyComponent.makfor Windows - Edit the makefile, changing the
GECKO_SDK_PATHvariable 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 Configurationsin the upper left corner. - Open the
C/C++tab and choosePreprocessorin theCategorydrop-down list. - Make sure that "Additional include directories" points to your Gecko SDK.
- Open the
Linktab and chooseInputin theCategorydrop-down list. - Make sure that the "Additional library path" points to your Gecko SDK.
- Open the project settings:
- Build the sample.
- Open a command shell (
cmdon Windows;tcsh,bash,xtermetc. on Linux). - Navigate to the sample src directory.
- On Linux issue a
makecommand.MyComponent.sofile is created. - On Windows issue a
nmake /f MyComponent.makcommand.Debug\MyComponent.dllis created. - Alternatively, on Windows, issue a
nmake /f "MyComponent.mak" CFG="MyComponent - Win32 Release"command for a release build.Release\MyComponent.dllis 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
- Select the wanted configuration (Debug/Release) in
- Open a command shell (
- Register the new component with Mozilla.
- Copy
MyComponent.so/MyComponent.dllandIMyComponent.xptfile 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
regxpcomcommand 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.datandcompreg.datfiles 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.autoregin 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.
- Copy
- Test the new component.
- Restart Mozilla.
- Open the
MyComponentTest.htmlfile 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
- IBM developerWorks - XPCOM Overview [part 1][part 2][part 3][part 4][part 5]
- Creating XPCOM Components by Doug Turner.
- Creating Applications With Mozilla [chapter 8 - XPCOM]
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
Dave wrote:
Kevin McAllister wrote:
Nat Brown wrote:
Jesse Watson wrote:
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?
free_zy wrote:
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
Anand Balaji wrote:
Could you provide me with any information as to how this component could be packaged and deployed via the Internet?
Thanks in advance.
Roman wrote:
Stan wrote:
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.
G.Naudts wrote:
Stan wrote:
anonymous wrote:
Is there any way to link these files automatically
anonymous wrote:
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?
ragevietnow wrote:
Santosh Ahuja wrote:
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 :)
Diego wrote:
I have Visual Studio 6 installed... i need VC 2003 or other c++ compilers, such CYGWIN?
Santosh Ahuja wrote:
Updated by Alex: I've now updated the tutorial and the sample and included a VC 6.0 project file. Thanks.
Ivo Stoyanoff wrote:
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"?
Alex wrote:
Corina wrote:
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.
Corina wrote:
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.
pierro81 wrote:
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.
Nick wrote:
stl wrote:
Am I missing something???
sky_water wrote:
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!
Tobias Wehrum wrote:
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...
Joe wrote:
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
Aditya wrote:
gr8 job alex.
thanks to kyr0 too.
kyr0 wrote:
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
Christian Wartena wrote:
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
benjamin wrote:
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.
Jan Wagner wrote:
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
Jan Wagner wrote:
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?
vishesh wrote:
Freddie wrote:
// 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 ??
anonymous wrote:
Hm... any ideas ?
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.
Sabarinathan wrote:
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
anonymous wrote:
noohgnas wrote:
omar wrote:
Thanks in advance.
anony wrote:
anonymous wrote:
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.
anony wrote:
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.
Marco wrote:
Geraint Edwards wrote:
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!
Phan Van Tuan wrote:
error while loading shared libraries: libxpcom.so: cannot open shared object file: No such file or directory
can you help me.
anonymous wrote:
pvtuan wrote:
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
alexis sepane wrote:
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
roland wrote:
Jay wrote:
roland wrote:
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);
}
roland wrote:
EKenDo wrote:
(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
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!
tom wrote:
tom wrote:
Boris wrote:
alexis sepane wrote:
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
huazilin wrote:
anonymous wrote:
Cool_dude wrote:
Can anyone help me out.
Thanks in advance.
Todd wrote:
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.
Todd wrote:
Jibril wrote:
cool_dude wrote:
Can anyone successful on registring the sample on linux please post their make file?
Thanks in advamnce
anonymous wrote:
remove -lxpcomglue from GECKO_LDFLAGS
put $(FILE) and libxpcomglue_s.a in front of GECKO_LDFLAGS
anonymous wrote:
[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]
Andrea wrote:
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.
Cool_dude wrote:
finally, made it to work on firefox 1.5.0.2 and linux.
girish wrote:
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
Andrea wrote:
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
girish wrote:
can anyone tell me what could be the problem with 1.8a1 version of gecko-sdk?
sciascid wrote:
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?
varmag wrote:
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
Sarjeet Singh wrote:
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 :)
cool_dude wrote:
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,
anonymous wrote:
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,
balaji patil wrote:
thanx in advance......
Andrew wrote:
So here's what you need: gecko-sdk-1.7.13 and VS 6.0 with sp5.
Good luck!
anonymous wrote:
Type error: Components.classes[cid] has no properties!
Any ideas?
anonymous wrote:
Type error: Components.classes[cid] has no properties!
Any ideas?
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
----------
Adi KR wrote:
-------------------------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.
anonymous wrote:
[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]#
Abhishek Kohli wrote:
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
Abhishek Kohli wrote:
Colin wrote:
http://ehleypnm.com/azqc/cpku.html | http://xthgsbzs.com/nuco/kezr.html
JDong wrote:
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 !!!
JDong wrote:
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.
Abhishek kohli wrote:
George Akpoly wrote:
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.
Farkbert wrote:
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...)
Sam Lie wrote:
'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.
anonymous wrote:
{?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 <>
anonymous wrote:
'components.classes[cid] has no properties' freaken error.
Sam Lie wrote:
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
Farkbert wrote:
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.
abhishek kohli wrote:
thanks
iunx frblki wrote:
cysl mhor wrote:
cysl mhor wrote:
cysl mhor wrote:
Mike wrote:
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?
Peous wrote:
- 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)
Garrett wrote:
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.
Dave Kok wrote:
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.
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
Dan wrote:
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
Dan wrote:
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
test wrote:
ajay wrote:
M7OT2Ft0Tl wrote:
Ian Malone wrote:
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).
sandor cristian wrote:
sandor cristian wrote:
Tomekk wrote:
Now It works
thx Sam Lie
Man From Russia wrote:
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????
Dev wrote:
I have looked all topics in this article and nothing help me.
How can I resolve this problem????
Dev wrote:
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!
PMT wrote:
My email: pmtyim@yahoo.com
PMT wrote:
My email: pmtyim@yahoo.com

2701




被折叠的 条评论
为什么被折叠?




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