rv = nsComponentManager::CreateInstance(kSoftwareUpdateCID, nsnull, NS_GET_IID(nsISoftwareUpdate), (void**) &gXPI);
rv = CallCreateInstance(kSoftwareUpdateCID, &gXPI);
PR_PUBLIC_API(nsresult) XPI_Init( const char*         aProgramDir,                                  const char*         aLogName,                                  pfnXPIProgress      progressCB ){    nsresult              rv;    //--------------------------------------------------------------------    // Initialize XPCOM and AutoRegister() its components    //--------------------------------------------------------------------#if defined(XP_WIN) || defined(XP_OS2) #ifdef XP_OS2_EMX    char componentPath[MAX_PATH];    _getcwd2(componentPath, MAX_PATH);    int len = strlen(componentPath);    for (int i = 0; i < len; i++) {      if (componentPath[i] == '/') {        componentPath[i] = '\\';      }    } #else    char componentPath[MAX_PATH];    getcwd(componentPath, MAX_PATH); #endif    nsCOMPtr<nsILocalFile> file;    rv = NS_NewNativeLocalFile(nsDependentCString(componentPath), PR_TRUE, getter_AddRefs(file));    if (NS_FAILED(rv)) return rv;        rv = NS_InitXPCOM2(&gServiceMgr, file, nsnull); #elif defined(XP_UNIX)    rv = NS_InitXPCOM2(&gServiceMgr, nsnull, nsnull);     char cwd[1024];    char compDirPath[1024];    memset(cwd, 0, 1024);    memset(compDirPath, 0, 1024);    getcwd(cwd, 1024);    sprintf(compDirPath, "%s/components", cwd);    nsCOMPtr<nsILocalFile> compDir;    NS_NewNativeLocalFile(nsDependentCString(compDirPath), PR_TRUE, getter_AddRefs(compDir));#else    rv = NS_InitXPCOM2(&gServiceMgr, NULL, NULL);#endif    if (NS_FAILED(rv))        return rv;    nsCOMPtr<nsIComponentRegistrar> registrar = do_QueryInterface(gServiceMgr);    NS_ASSERTION(registrar, "Null nsIComponentRegistrar");#if defined(XP_UNIX)    rv = registrar->AutoRegister(compDir);#else    rv = registrar->AutoRegister(nsnull);#endif    if (NS_FAILED(rv))        return rv;    //--------------------------------------------------------------------    // Get the SoftwareUpdate (XPInstall) service.    //    // Since AppShell is not started by XPIStub the XPI service is never     // registered with the service manager. We keep a local pointer to it     // so it stays alive througout.    //--------------------------------------------------------------------    rv = nsComponentManager::CreateInstance(kSoftwareUpdateCID,                                             nsnull,                                            NS_GET_IID(nsISoftwareUpdate),                                            (void**) &gXPI);    if (NS_FAILED(rv))        return rv;    //--------------------------------------------------------------------    // Override XPInstall's natural assumption that the current executable    // is Mozilla. Use the given directory as the "Program" folder.    //--------------------------------------------------------------------    nsCOMPtr<nsPIXPIStubHook>   hook = do_QueryInterface(gXPI);    nsCOMPtr<nsILocalFile>      iDirSpec;      if (aProgramDir)    {	NS_NewNativeLocalFile(nsDependentCString(aProgramDir), PR_TRUE, getter_AddRefs(iDirSpec));    }    else    {       nsCOMPtr<nsIProperties> directoryService =           do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID, &rv);       directoryService->Get(NS_XPCOM_CURRENT_PROCESS_DIR, NS_GET_IID(nsILocalFile),                              getter_AddRefs(iDirSpec));    }    if (hook && iDirSpec)    {        rv = hook->StubInitialize( iDirSpec, aLogName );        if (NS_FAILED(rv)) return rv;    }    else        return NS_ERROR_NULL_POINTER;    //--------------------------------------------------------------------    // Save the install wizard's callbacks as a nsIXPINotifer for later    //--------------------------------------------------------------------    nsStubListener* stub = new nsStubListener( progressCB );    if (!stub)    {        gXPI->Release();        rv = NS_ERROR_OUT_OF_MEMORY;    }    else    {        rv = stub->QueryInterface(NS_GET_IID(nsIXPIListener), (void**)&gListener);    }    return rv;}