Я успешно установил файл DLL в Thunderbird.Но в моем XPCOMViewer я могу найти только интерфейс, но не класс, поэтому, когда я использую компонент, он показывает мне ошибку: TypeError: Components.classes [cid] не определен
Вот мои все файлы:
Дорогие все,
Я успешно установил файл DLL в Thunderbird.Но в моем XPCOMViewer я могу найти только интерфейс, но не класс, поэтому, когда я использую компонент, он показывает мне ошибку: TypeError: Components.classes [cid] не определен
Вот мои все файлы:
// IMyComponent.idl
#include "nsISupports.idl"
[scriptable, uuid(4782615C-5ACD-11E0-AE9B-68F4DFD72085)]
interface IMyComponent : nsISupports
{
long Add(in long a, in long b);
};
//IMyComponent.h
/*
* DO NOT EDIT. THIS FILE IS GENERATED FROM IMyComponent.idl
*/
#ifndef __gen_IMyComponent_h__
#define __gen_IMyComponent_h__
#ifndef __gen_nsISupports_h__
#include "nsISupports.h"
#endif
/* For IDL files that don't want to include root IDL files. */
#ifndef NS_NO_VTABLE
#define NS_NO_VTABLE
#endif
/* starting interface: IMyComponent */
#define IMYCOMPONENT_IID_STR "4782615c-5acd-11e0-ae9b-68f4dfd72085"
#define IMYCOMPONENT_IID \
{0x4782615c, 0x5acd, 0x11e0, \
{ 0xae, 0x9b, 0x68, 0xf4, 0xdf, 0xd7, 0x20, 0x85 }}
class NS_NO_VTABLE NS_SCRIPTABLE IMyComponent : public nsISupports {
public:
NS_DECLARE_STATIC_IID_ACCESSOR(IMYCOMPONENT_IID)
/* long Add (in long a, in long b); */
NS_SCRIPTABLE NS_IMETHOD Add(PRInt32 a, PRInt32 b, PRInt32 *_retval NS_OUTPARAM) = 0;
};
NS_DEFINE_STATIC_IID_ACCESSOR(IMyComponent, IMYCOMPONENT_IID)
/* Use this macro when declaring classes that implement this interface. */
#define NS_DECL_IMYCOMPONENT \
NS_SCRIPTABLE NS_IMETHOD Add(PRInt32 a, PRInt32 b, PRInt32 *_retval NS_OUTPARAM);
/* Use this macro to declare functions that forward the behavior of this interface to another object. */
#define NS_FORWARD_IMYCOMPONENT(_to) \
NS_SCRIPTABLE NS_IMETHOD Add(PRInt32 a, PRInt32 b, PRInt32 *_retval NS_OUTPARAM) { return _to Add(a, b, _retval); }
/* Use this macro to declare functions that forward the behavior of this interface to another object in a safe way. */
#define NS_FORWARD_SAFE_IMYCOMPONENT(_to) \
NS_SCRIPTABLE NS_IMETHOD Add(PRInt32 a, PRInt32 b, PRInt32 *_retval NS_OUTPARAM) { return !_to ? NS_ERROR_NULL_POINTER : _to->Add(a, b, _retval); }
#if 0
/* Use the code below as a template for the implementation class for this interface. */
/* Header file */
class _MYCLASS_ : public IMyComponent
{
public:
NS_DECL_ISUPPORTS
NS_DECL_IMYCOMPONENT
_MYCLASS_();
private:
~_MYCLASS_();
protected:
/* additional members */
};
/* Implementation file */
NS_IMPL_ISUPPORTS1(_MYCLASS_, IMyComponent)
_MYCLASS_::_MYCLASS_()
{
/* member initializers and constructor code */
}
_MYCLASS_::~_MYCLASS_()
{
/* destructor code */
}
/* long Add (in long a, in long b); */
NS_IMETHODIMP _MYCLASS_::Add(PRInt32 a, PRInt32 b, PRInt32 *_retval NS_OUTPARAM)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* End of implementation class template. */
#endif
#endif /* __gen_IMyComponent_h__ */
//MyComponentModule.cpp
#include "nsIGenericFactory.h"
#include "MyComponent.h"
NS_GENERIC_FACTORY_CONSTRUCTOR(MyComponent)
static nsModuleComponentInfo components[] =
{
{
MY_COMPONENT_CLASSNAME,
MY_COMPONENT_CID,
MY_COMPONENT_CONTRACTID,
MyComponentConstructor,
}
};
NS_IMPL_NSGETMODULE("MyComponentsModule", components)
//MyComponent.h
#ifndef _MY_COMPONENT_H_
#define _MY_COMPONENT_H_
#include "IMyComponent.h"
#define MY_COMPONENT_CONTRACTID "@mozilla.org/XPCOMSample/MyComponent;1"
#define MY_COMPONENT_CLASSNAME "A Simple XPCOM Sample"
#define MY_COMPONENT_CID {0x4782615c, 0x5acd, 0x11e0, \
{ 0xae, 0x9b, 0x68, 0xf4, 0xdf, 0xd7, 0x20, 0x85 }}
/* Header file */
class MyComponent : public IMyComponent
{
public:
NS_DECL_ISUPPORTS
NS_DECL_IMYCOMPONENT
MyComponent();
virtual ~MyComponent();
/* additional members */
};
#endif //_MY_COMPONENT_H_
//MyComponent.cpp
#include "MyComponent.h"
NS_IMPL_ISUPPORTS1(MyComponent, IMyComponent)
MyComponent::MyComponent()
{
/* member initializers and constructor code */
}
MyComponent::~MyComponent()
{
/* destructor code */
}
/* long Add (in long a, in long b); */
NS_IMETHODIMP MyComponent::Add(PRInt32 a, PRInt32 b, PRInt32 *_retval)
{
*_retval = a + b;
return NS_OK;
}
My makefile:
CC=cl.exe
CCPARMS=/D "XP_WIN" /D "XP_WIN32"
all: MyComponent.obj MyComponentModule.obj link
MyComponent.obj:
$(CC) $(CCPARMS) /c MyComponent.cpp
MyComponentModule.obj:
$(CC) $(CCPARMS) /c MyComponentModule.cpp
link:
link.exe /DLL /out:"MyComponent.dll" /implib:"MyComponent.lib" /machine:I386 xpcom.lib xpcomglue_s.lib nspr4.lib "MyComponent.obj" "MyComponentModule.obj"
clean:
del *.lib *.dll *.obj *.exp