首页 > 其他 > 详细

(FFOS Gecko) - several ways of using a XPCOM Service

时间:2015-07-20 19:07:14      阅读:238      评论:0      收藏:0      [点我收藏+]

1. Using a service in C++

 

nsCOMPtr<nsIServiceManager> servManager;
nsresult rv = NS_GetServiceManager(getter_AddRefs(servManager));
if (NS_FAILED(rv)) { // get ServiceManager error
  return -1;
}

// get real Service
nsCOMPtr<nsICustomService> customService;
rv = servMan->GetServiceByContractID("@mozilla.org/customservice",
                                     NS_GET_IID(nsICustomService),
                                     getter_AddRefs(customService));
if (NS_FAILED(rv)) { // get CustomService error
  return -1;
}

// call a method of CustomService
customService->callMethod(/*some parameters*/);

 

2. Using a service in Javascript(XPConnect)

 

customService = Components.classes["@mozilla.org/customservice;1"]
                 .getService();
customService = customService.QueryInterface(Components.interfaces.nsICustomService);
customService.callMethod();

 

(FFOS Gecko) - several ways of using a XPCOM Service

原文:http://www.cnblogs.com/code-4-fun/p/4661738.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!