xpcom回调js的问题

梧桐168 2010-04-09 04:01:25
之前我发了相关的帖子
http://topic.csdn.net/u/20100408/09/9c311246-67c3-4681-8216-ce1d2287ebfa.html
现在基本上可以回调了,但我的用例子中的代码,register函数不起作用,
用在function MyComponentTestGo()加如下代码才行


my_xpcom.addObserver(my_observer, "myTopicID", false);


我想了解下一般的注册语句该怎么写,用例子里的如下方法为何不行

register: function()
{
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
const cid = "@mozilla.org/observer-service;1";
//const cid = "@yoursite.com/MyXPCOM1;1";
var observerService = Components.classes[cid].getService(Components.interfaces.nsIObserverService);
observerService.addObserver(this, "myTopicID", false);
},

...全文
115 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
oyljerry 2010-04-09
  • 打赏
  • 举报
回复
你注册成功后,C++中用NotifyObservers通知所有的observer,然后对应的js中对应callback等来处理
sgzwiz 2010-04-09
  • 打赏
  • 举报
回复
因为你的CMyXPCOM1::NotifyObservers()写的不对,你理解错了。
nsresult
nsWebShellWindow::NotifyObservers( const nsString &aTopic, const nsString &someData ) {
nsresult rv = NS_OK;
// Get observer service.
nsIObserverService *svc = 0;
rv = nsServiceManager::GetService( "@mozilla.org/observer-service;1",
NS_GET_IID(nsIObserverService),
(nsISupports**)&svc );
if ( NS_SUCCEEDED( rv ) && svc ) {
// Notify observers as instructed; the subject is "this" web shell window.
nsCAutoString topic; topic.Assign(prefix);
topic.Append(";");
topic.AppendWithConversion(aTopic);
rv = svc->NotifyObservers( (nsIWebShellWindow*)this, topic.get(), someData.get() );
// Release the service.
nsServiceManager::ReleaseService( "@mozilla.org/observer-service;1", svc );
} else {
}
return rv;
}

svc->NotifyObservers()会自动调用所有observer的observe(),而你m_pObserver->Observe(aSubject, aTopic, someData);这个属于毫无意义的代码。

3,245

社区成员

发帖
与我相关
我的任务
社区描述
ATL,Active Template Library活动(动态)模板库,是一种微软程序库,支持利用C++语言编写ASP代码以及其它ActiveX程序。
社区管理员
  • ATL/ActiveX/COM社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧