subst o: d:\myworkfolder\_firefox
- in this folder we will add all the necessary files.
set path=%path%;O:\xulrunner-sdk\bin;O:\xulrunner-sdk\sdk\bin
cmd.exe
#include "nsISupports.idl"
#include "nsrootidl.idl"
[ scriptable , uuid ( CB934085 - D019 - 47d5 - A6F0 - 623885873281 ) ]
interface IDemo : nsISupports
{
long func1 ( in long inP , out long outP ) ;
long func2 ( in wstring inP , out wstring outP ) ;
} ;
set path=%path%;O:\xulrunner-sdk\bin;O:\xulrunner-sdk\sdk\bin
xpidl -IO:\xulrunner-sdk\idl -m header IDemo.idl
xpidl -IO:\xulrunner-sdk\idl -m typelib IDemo.idl
#ifndef _DEMO_H_
#define _DEMO_H_
#include "IDemo.h"
#define DEMO_CONTRACTID "@demo.com/XPCOMDemo/Demo;1"
#define DEMO_CLASSNAME "XPCOM Demo LOL"
#define DEMO_CID { 0xcb934086 , 0xd019 , 0x47d5 , { 0xa6 , 0xf0 , 0x62 , 0x38 , 0x85 , 0x87 , 0x32 , 0x81 } }
class Demo : public IDemo
{
public :
NS_DECL_ISUPPORTS
NS_DECL_IDEMO
Demo ( ) ;
virtual ~ Demo ( ) ;
} ;
#endif
#include "Demo.h"
#include < nsMemory . h >
#include < nsStringAPI . h >
NS_IMPL_ISUPPORTS1 ( Demo , IDemo )
Demo : : Demo ( ) {
}
Demo : : ~ Demo ( ) {
}
NS_IMETHODIMP Demo : : Func1 ( PRInt32 inP , PRInt32 * outP , PRInt32 * _retval ) {
if ( inP > 100 ) {
* _retval = 1 ;
* outP = 0 ;
} else {
* _retval = 0 ;
* outP = inP * 2 ;
}
return NS_OK ;
}
NS_IMETHODIMP Demo : : Func2 ( const PRUnichar * inP , PRUnichar * * outP , PRInt32 * _retval ) {
const wchar_t * msg = L "" ;
* outP = ( PRUnichar * ) nsMemory : : Clone ( msg , ( wcslen ( msg ) + 1 ) * sizeof ( wchar_t ) ) ;
* _retval = 0 ;
return NS_OK ;
}
#include "nsIGenericFactory.h"
#include "Demo.h"
NS_GENERIC_FACTORY_CONSTRUCTOR ( Demo )
static nsModuleComponentInfo components [ ] =
{
{
DEMO_CLASSNAME ,
DEMO_CID ,
DEMO_CONTRACTID ,
DemoConstructor ,
}
} ;
NS_IMPL_NSGETMODULE ( "DemoModule" , components )
set path=%path%;O:\xulrunner-sdk\bin;O:\xulrunner-sdk\sdk\bin
del /f "C:\Documents and Settings\test\Application Data\Mozilla\Firefox\Profiles\dev\xpti.dat"
del /f "C:\Documents and Settings\test\Application Data\Mozilla\Firefox\Profiles\dev\compreg.dat"
copy /Y IDemo.xpt "C:\Program Files\Mozilla Firefox\components\"
copy /Y debug\Demo.dll "C:\Program Files\Mozilla Firefox\components\"
netscape . security . PrivilegeManager . enablePrivilege ( "UniversalXPConnect" ) ;
obj = Components . classes [ "@demo.com/XPCOMDemo/Demo;1" ] . createInstance ( ) ; // ? Demo.h
myobject = obj . QueryInterface ( Components . interfaces . IDemo ) ;
var x = { } ;
var res = myobject . func1 ( 10 , x ) ;
alert ( 'func1(10,x) returned ' + res + '. x is ' + x . value ) ;
res = myobject . func2 ( "asd" , x ) ;
alert ( 'func2("ads",x) returned ' + res + '. x is ' + x . value ) ;
Source: https://habr.com/ru/post/53312/