ffmaomao 发表于 2008-08-12 15:43

关于使用firefox中Gecko的问题

我准备用firefox的库解析HTML,其中要使用到里面的Gecko模块。

但是,在使用的时候老是无法创建 nsIHTMLContentSink 的对象。。

返回的错误信息是: NS_ERROR_FACTORY_NOT_REGISTERED

初步估计是在初始化的时候,没有将创建这个对象的工厂载入或者注册。

以下是我的代码:





#include <iostream>
#include "nsXPCOM.h"

#include "nsIComponentManager.h"
#include "nsComponentManagerUtils.h"

#include "nsParserCIID.h"
#include "nsIParser.h"
#include "nsIHTMLContentSink.h"

#include "nsContentCID.h"
#include "nsIDocument.h"
#include "nsIDOMHTMLDocument.h"


using namespace std;


// Class IID's

static NS_DEFINE_CID(kParserCID, NS_PARSER_CID);
static NS_DEFINE_CID(kLoggingSinkCID, NS_LOGGING_SINK_CID);


nsresult ParseData() {

&nbsp;&nbsp;nsresult result = NS_OK;


&nbsp;&nbsp;// Create a parser

&nbsp;&nbsp;nsCOMPtr<nsIParser> parser(do_CreateInstance(kParserCID, &result));
&nbsp;&nbsp;if (NS_FAILED(result)) {
&nbsp;&nbsp;&nbsp;&nbsp;printf("\nUnable to create a parser\n");
&nbsp;&nbsp;&nbsp;&nbsp;return result;
&nbsp;&nbsp;}


&nbsp;&nbsp;// Create a sink

&nbsp;&nbsp;nsCOMPtr<nsILoggingSink> sink(do_CreateInstance(kLoggingSinkCID, &result));

/**此处无法创建 nsILoggingSink 对象(nsIHTMLContentSink是其父类)*/

&nbsp;&nbsp;if (NS_FAILED(result)) {
&nbsp;&nbsp;&nbsp;&nbsp;printf("\nUnable to create a sink\n");
&nbsp;&nbsp;&nbsp;&nbsp;return result;
&nbsp;&nbsp;}

}


//---------------------------------------------------------------------


int main(int argc, char** argv)
{

&nbsp;&nbsp;nsresult rv = NS_InitXPCOM2(nsnull, nsnull, nsnull);

&nbsp;&nbsp;if (NS_FAILED(rv)) {
&nbsp;&nbsp;&nbsp;&nbsp;printf("NS_InitXPCOM2 failed\n");
&nbsp;&nbsp;&nbsp;&nbsp;return -1;
&nbsp;&nbsp;}

&nbsp;&nbsp; ParseData();

&nbsp;&nbsp;return 0;
}

qliu00 发表于 2008-08-13 22:40

无法创建 nsIHTMLContentSink ,肯定是默认链接有问题,你可以重装一下

或者修复一下firefox的库解析

yaolixing 发表于 2017-07-21 02:31

他山界面开发框架 v22是一套基于Gecko v22 的开源收费跨平台界面解决方案。可使用xul, html(5), css(3), js 开发界面,支持js, c++互调,发行包大小13MB 。

yaolixing 发表于 2017-07-21 02:39

他山界面开发框架 v22是一套基于Gecko v22 的开源收费跨平台界面解决方案。可使用xul, html(5), css(3), js 开发界面,支持js, c++互调,发行包大小13MB
页: [1]
查看完整版本: 关于使用firefox中Gecko的问题