nsIAcceptLang* Aservice = nsnull; ret = nsServiceManager::GetService(kAcceptLangCID, kIAcceptLangIID, (nsISupports**) &Aservice); if (NS_FAILED(ret)) { printf("cannot create AcceptLang service\n"); return 1; } printf("\n ** created AcceptLang service\n");
main(int argc, char *argv[]){  nsresult ret;  NS_AutoregisterComponents();  nsIStringBundleService* service = nsnull;  ret = nsServiceManager::GetService(kStringBundleServiceCID,                                     kIStringBundleServiceIID, (nsISupports**) &service);  if (NS_FAILED(ret)) {    printf("cannot create service\n");    return 1;  }  nsIAcceptLang* Aservice = nsnull;  ret = nsServiceManager::GetService(kAcceptLangCID,                                     kIAcceptLangIID, (nsISupports**) &Aservice);  if (NS_FAILED(ret)) {    printf("cannot create AcceptLang service\n");    return 1;  }    printf("\n ** created AcceptLang service\n");  nsIStringBundle* bundle = nsnull;  ret = service->CreateBundle(TEST_URL, &bundle);  if (NS_FAILED(ret)) {    printf("cannot create instance\n");    return 1;  }  nsAutoString v;  v.AssignWithConversion("");  PRUnichar *ptrv = nsnull;  char *value = nsnull;  // 123  ret = bundle->GetStringFromID(123, &ptrv);  if (NS_FAILED(ret)) {    printf("cannot get string from ID 123, ret=%d\n", ret);    return 1;  }  v = ptrv;  value = ToNewCString(v);  cout << "123=\"" << value << "\"" << endl;  // file  nsString strfile;  strfile.AssignWithConversion("file");  const PRUnichar *ptrFile = strfile.get();  ret = bundle->GetStringFromName(ptrFile, &ptrv);  if (NS_FAILED(ret)) {    printf("cannot get string from name\n");    return 1;  }  v = ptrv;  value = ToNewCString(v);  cout << "file=\"" << value << "\"" << endl; nsIBidirectionalEnumerator* propEnum = nsnull;  ret = bundle->GetEnumeration(&propEnum);  if (NS_FAILED(ret)) {    printf("cannot get enumeration\n");    return 1;  }  ret = propEnum->First();  if (NS_FAILED(ret))  {  printf("enumerator is empty\n");  return 1;  }  cout << endl << "Key" << "\t" << "Value" << endl;  cout <<		  "---" << "\t" << "-----" << endl;  while (NS_SUCCEEDED(ret))  {    nsIPropertyElement* propElem = nsnull;    ret = propEnum->CurrentItem((nsISupports**)&propElem);    if (NS_FAILED(ret)) {    printf("failed to get current item\n");    return 1;    }    PRUnichar *pKey = nsnull;    PRUnichar *pVal = nsnull;    ret = propElem->GetKey(&pKey);    if (NS_FAILED(ret)) {      printf("failed to get current element's key\n");      return 1;    }    ret = propElem->GetValue(&pVal);    if (NS_FAILED(ret)) {      printf("failed to get current element's value\n");      return 1;    }    nsAutoString keyAdjustedLengthBuff(pKey);    nsAutoString valAdjustedLengthBuff(pVal);    char* keyCStr = ToNewCString(keyAdjustedLengthBuff);    char* valCStr = ToNewCString(valAdjustedLengthBuff);    if (keyCStr && valCStr)     cout << keyCStr << "\t" << valCStr << endl;    delete[] keyCStr;    delete[] valCStr;    delete[] pKey;    delete[] pVal;    ret = propEnum->Next();  }  return 0;}