繁体   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