码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2015-07-20 19:09:40      阅读:139      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!