nsIServiceManager *pnsIServiceManager = NULL; if (NS_FAILED(serviceMgr->QueryInterface(kIServiceManagerIID, (void**) &pnsIServiceManager))) return NS_ERROR_FAILURE;
nsresult rv; nsCOMPtr<nsIServiceManager> servMgr = do_QueryInterface(serviceMgr, &rv); if (NS_FAILED(rv)) return rv;
NSGetFactory(nsISupports* serviceMgr,             const nsCID &aClass,             const char *aClassName,             const char *aProgID,             nsIFactory **aFactory){  if (nsnull == aFactory) {    return NS_ERROR_NULL_POINTER;  }  nsIServiceManager *pnsIServiceManager = NULL;  if (NS_FAILED(serviceMgr->QueryInterface(kIServiceManagerIID, (void**) &pnsIServiceManager)))    return NS_ERROR_FAILURE;  *aFactory = new nsPluginFactory(aClass, pnsIServiceManager);  serviceMgr->Release();  if (nsnull == aFactory) {    return NS_ERROR_OUT_OF_MEMORY;  }  return (*aFactory)->QueryInterface(kIFactoryIID, (void**)aFactory);}