moztorch
| resources: | Home Mailing List Installation Source Code Members Screenshots |
|---|
Creating a new Component (Win32)
This guide is intended to walk the reader through setting up a skeleton XPCOM project in Microsoft Visual Studio 6.0. Familiarity with XPIDL and C++ is assumed.Download the following packages:
- Gecko SDK (Win32, Linux) - Provides headers, libs, and IDL files for FROZEN XPCOM interfaces.
- Mozilla Windows Tools - Provides libIDL-X.dll required to process IDL files.
Configure Environment:
- Set
MOZ_TOOLSenvironment variable to path where you'd like WinTools to install (we'll call it$TOOLDIR). - Unpack
wintools.zip, and runbuildtools\windows\install.bat - Add
$TOOLDIR\bintoPATHenvironment variable. - Unpack Gecko SDK wherever you like (we'll call the path
$SDK). - Add
$SDK\bintoPATHenvironment variable.
Setup new Visual Studio project for XPCOM component:
- Create new VS project "Win32 Dynamic-Link Library"
- Under "C/C++" tab, goto "Preprocessor" Category
- Add following preprocessor defines: "XPCOM_GLUE"
- Add sdk include dir to "Additional Include Directories" box
- Goto "C++ Language" Category
- Disable exception handling
- Under "Link" tab, goto "Input" category
- Add sdk "bin" dir to "Additional Library Path" box
- Add following libraries to the "Object/library Modules" box: "xpcomglue.lib nspr4.lib plds4.lib plc4.lib"
- Under "C/C++" tab, goto "Code Generation" Category
- Select "Multithreaded DLL" for "Use runtime library" box
Create Interface Definition: $IDL.idl
- generate GUID (genguid.exe)
- write interface definition
- generate header and typelib from interface file (assuming gecko-sdk lives at
$SDK) xpidl -m header -I $SDK/idl $IDL.idlxpidl -m typelib -I $SDK/idl $IDL.idl- this creates
$IDL.hand$IDL.xpt - For more information, see mtIMachine.idl.
Create Component Header File: $COMPONENT.h
- add double inclusion protection
#include "$IDL.h"- generate GUID
- Create component constants:
#define ${COMPONENT}_CONTRACTID "@cs.pdx.edu/MozTorch/WebLock;1" #define ${COMPONENT}_CLASSNAME "MozTorch WebLock Example" // {4D598E8A-B69C-4826-B40B-90FE8F80286C} #define ${COMPONENT}_CID { 0x4d598e8a, 0xb69c, 0x4826, { 0xb4, 0xb, 0x90, 0xfe, 0x8f, 0x80, 0x28, 0x6c } } - copy header file template from
$IDL.h(replacing component name) - For more information, see mtMachineKnn.h.
Create Component Source File: $COMPONENT.cpp
#include $COMPONENT.h- copy source file template from
$IDL.h(replacing component name) - For more information, see mtMachineKnn.cpp.
Create Module Source File: ${COMPONENT}Module.cpp
#include "nsIGenericFactory.h"#include "COMPONENT.h"NS_GENERIC_FACTORY_CONSTRUCTOR($COMPONENT)-
static nsModuleComponentInfo components[] = {{ ${COMPONENT}_CLASSNAME, ${COMPONENT}_CID, ${COMPONENT}_CONTRACTID, ${COMPONENT}Constructor, }}; NS_IMPL_NSGETMODULE("${COMPONENT}Module", components)- For more information, see mtModule.cpp.
Build the component: $COMPONENT.dll
Register Component with Firefox
- copy
$COMPONENT.dlland$IDL.xptto Firefox components dir - run regxpcom (might need "
-x $COMPONENTS_DIR") - touch "
.autoreg" in main firefox dir