nsComponentManager::CreateInstance(kTestFactoryCID, NULL, NS_GET_IID(ITestClass), (void **) &t);
CallCreateInstance(kTestFactoryCID, &t);
int main(int argc, char **argv) {  nsresult rv;  {    nsCOMPtr<nsIServiceManager> servMan;    rv = NS_InitXPCOM2(getter_AddRefs(servMan), nsnull, nsnull);    if (NS_FAILED(rv)) return -1;    nsCOMPtr<nsIComponentRegistrar> registrar = do_QueryInterface(servMan);    NS_ASSERTION(registrar, "Null nsIComponentRegistrar");    if (registrar)      registrar->RegisterFactory(kTestFactoryCID,                                 nsnull,                                 nsnull,                                 new TestFactory());    ITestClass *t = NULL;    nsComponentManager::CreateInstance(kTestFactoryCID,                                       NULL,                                       NS_GET_IID(ITestClass),                                       (void **) &t);    if (t != NULL) {      t->Test();      t->Release();    } else {      printf("CreateInstance failed\n");    }    t = NULL;    nsComponentManager::CreateInstance(kTestLoadedFactoryCID,                                       NULL,                                       NS_GET_IID(ITestClass),                                       (void **) &t);    if (t != NULL) {      t->Test();      t->Release();    } else {      printf("Dynamic CreateInstance failed\n");    }  } // this scopes the nsCOMPtrs  // no nsCOMPtrs are allowed to be alive when you call NS_ShutdownXPCOM  rv = NS_ShutdownXPCOM(nsnull);  NS_ASSERTION(NS_SUCCEEDED(rv), "NS_ShutdownXPCOM failed");  return 0;}