2011-03-31 31 views
1

我有成功的安裝我的dll文件雷鳥。但在我XPCOMViewer我只能找到接口而不是類,所以,當我使用的組件,它顯示了我的錯誤: 類型錯誤:Components.classes [CID]是不確定的使用XPCOM註冊dll文件時,我可以獲取界面,但無法獲得類!

這裏是我的所有文件:

尊敬的大家,

我已成功安裝我的dll文件到雷鳥。但在我XPCOMViewer我只能找到接口而不是類,所以,當我使用的組件,它顯示了我的錯誤: 類型錯誤: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 
+0

你所說的「安裝」是什麼意思? – Neil 2011-04-05 23:20:28

回答

0

TypeError: Components.classes[cid] is undefined

這表明你的組件安裝不正確。

這裏的步驟,以在FF 3.6

  • 複製.dll和.xpt文件安裝新的XPCOM組件到<的%ProgramFiles%\ Mozilla Firefox的\組件>目錄
  • 在%ProgramFiles%\ Mozilla Firefox \ components目錄中,有一個名爲「componets.list」的文件。只需在您的DLL文件的添加名稱,這將迫使註冊
  • 現在firefox.exe盯着之前,從您的個人資料目錄中刪除的compreg.dat和xpti.dat文件。

啓動Firefox現在和你的組件必須自動註冊。

+0

這是做的手工方式,這將是更好地包裝在一個XPI文件擴展名和分發,因爲不是每個人都希望有這樣的文件撥弄。 – 2012-01-14 17:36:06

0

添加到您的install.rdf,根據描述部分:

<em:unpack>true</em:unpack> 

如:

<Description about="urn:mozilla:install-manifest"> 
    <em:id>[email protected]</em:id> 
    <em:version>1.0</em:version> 
    <em:type>2</em:type> 
    <em:unpack>true</em:unpack> 
    ... 

這是因爲XPCOM的二進制文件要求進行解包是可用見文件: https://developer.mozilla.org/en/Install_Manifests

下解壓。

相關問題