1

我需要创建一个调用 C++ 代码的 Firefox 插件。我做了一些研究,发现这个教程让我开始:http ://briankrausz.com/building-ac-xpcom-component-in-windows/

我遵循了所有步骤,但陷入了需要使用 VS 编译代码的部分。我正在使用 VS 2005。

更具体地说,我有一个包含 2 个头文件 ( IMyComponent.h& MyComponent.h) 和 2 个 cpp 文件 ( MyComponent.cpp& MyComponentModule.cpp) 的项目。

每个 cpp 文件都配置为在不支持 CLR 且不带预编译头的情况下进行编译。

但是,当我尝试编译时,我收到 3 条 C2​​440 错误消息,它们对应于以下代码行:

//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;
 };
4

1 回答 1

1

第一个错误是因为您试图传入 achar *而不是所需的类型。本页: 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}}
于 2012-08-01T21:49:07.453 回答