我需要创建一个调用 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 条 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;
};