簡體   English   中英

嘗試編譯XPCOM代碼時為什么會出現錯誤C2440?

[英]Why do I get error C2440 when I try to compile XPCOM code?

我需要創建一個調用C ++代碼的Firefox插件。 我進行了一些研究,發現該教程可以幫助我入門: http : //briankrausz.com/building-ac-xpcom-component-in-windows/

我遵循了所有步驟,但陷入了需要使用VS編譯代碼的部分。 我正在使用VS 2005。

更具體地說,我有一個項目,其中包含2個頭文件( IMyComponent.hMyComponent.h )以及2個cpp文件( MyComponent.cppMyComponentModule.cpp )。

每個cpp文件都配置為在沒有CLR支持且沒有預編譯頭的情況下進行編譯。

但是,當我嘗試編譯時,收到3條C2440錯誤消息,它們對應於以下代碼行:

//MyComponentModule.cpp

#include "nsIGenericFactory.h"
#include "MyComponent.h"

NS_GENERIC_FACTORY_CONSTRUCTOR(MyComponent)

static nsModuleComponentInfo components[] =
{
    {
      MY_COMPONENT_CLASSNAME,
      MY_COMPONENT_CID,          //'initializing': cannot convert from const char[37]    to PRUint32
      MY_COMPONENT_CONTRACTID, //'initializing': cannot convert from const char[39] to    PRUint16
      MyComponentConstructor, //'initializing': cannot convert from nsresult (__stdcall *)(nsISupports *, const nsIID &, void **) to PRUint16
   }
};

NS_IMPL_NSGETMODULE("MyComponentsModule", components)

在對應的頭文件中,我有以下代碼:

//MyComponent.h

#ifndef _MY_COMPONENT_H_
#define _MY_COMPONENT_H_

#include "IMyComponent.h"

#define MY_COMPONENT_CONTRACTID "@example.com/XPCOMSample/MyComponent;1"
#define MY_COMPONENT_CLASSNAME "A Simple XPCOM Sample"
#define MY_COMPONENT_CID "4c6f45e0-6366-4c69-Ab68-bb3c75cdada3"

class MyComponent : public IMyComponent
{
public:
 NS_DECL_ISUPPORTS
 NS_DECL_IMYCOMPONENT

 MyComponent();

private:
  ~MyComponent();

protected:
  /* additional members */
};

#endif //_MY_COMPONENT_H_

所有其他代碼都是使用Gecko SDK隨附的xpidl.exe工具生成的。

有人可以給點提示嗎?

PS:這是nsModuleComponentInfo:

 struct nsModuleComponentInfo {
 const char*                                 mDescription;
 nsCID                                       mCID;
 const char*                                 mContractID;
 NSConstructorProcPtr                        mConstructor;
 NSRegisterSelfProcPtr                       mRegisterSelfProc;
 NSUnregisterSelfProcPtr                     mUnregisterSelfProc;
 NSFactoryDestructorProcPtr                  mFactoryDestructor;
 NSGetInterfacesProcPtr                      mGetInterfacesProc;
 NSGetLanguageHelperProcPtr                  mGetLanguageHelperProc;
 nsIClassInfo **                             mClassInfoGlobal;
 PRUint32                                    mFlags;
 };

第一個錯誤是因為您試圖傳遞char *而不是必需的類型。 此頁面: https//developer.mozilla.org/en/Adding_XPCOM_components_to_Mozilla_build_system

至少提到如何處理CID參數:

{ "Friendly class description for people to read",
 YOUR_CLASS_CID,
 YOUR_CLASS_CONTRACTID,
 nsYourConcreteClassNameConstructor }

/* 2d96b3d0-c051-11d1-a827-0040959a28c9 */
#define NS_WINDOW_CID \
{ 0x2d96b3d0, 0xc051, 0x11d1, \
{0xa8, 0x27, 0x00, 0x40, 0x95, 0x9a, 0x28, 0xc9}}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM