Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

117 lines
3.5 KiB

  1. /*=========================================================================*
  2. |
  3. | |
  4. | Copyright 1995 by Microsoft Corporation |
  5. | KevinGj - January 1997 |
  6. | |
  7. |=========================================================================|
  8. | LangInfo.cpp : Locale/Language information |
  9. *=========================================================================*/
  10. #include <cdlpch.h>
  11. //=======================================================================//
  12. HRESULT GetLangStringMod(HMODULE hMod, LCID localeID, char *szThisLang, int iLen);
  13. //**********nSize needs to be greater than 2 at least.
  14. BOOL CLangInfo::GetAcceptLanguageString(LCID Locale, char *szAcceptLngStr, int nSize)
  15. {
  16. CHAR szThisLang[MAX_PATH];
  17. BOOL bRetVal = TRUE;
  18. HRESULT hr;
  19. if (!m_hMod)
  20. {
  21. m_hMod = LoadLibrary("mlang.dll");
  22. }
  23. if (!m_hMod)
  24. {
  25. bRetVal = FALSE;
  26. goto Exit;
  27. }
  28. hr = GetLangStringMod(m_hMod, Locale, szThisLang, sizeof(szThisLang));
  29. if (SUCCEEDED(hr))
  30. {
  31. if (lstrlenA(szThisLang) < nSize)
  32. {
  33. strcpy(szAcceptLngStr, szThisLang);
  34. DEBUG_PRINT(DOWNLOAD,
  35. INFO,
  36. ("CLangInfo::GetAcceptLanguageString::this=%#x, szAcceptLngStr=%.10q\n",
  37. this, szAcceptLngStr
  38. ));
  39. }
  40. else
  41. {
  42. bRetVal = FALSE;
  43. }
  44. goto Exit;
  45. }
  46. LCID lcid = (NULL);
  47. char szLocaleStr[10];
  48. lcid = GetPrimaryLanguageInfo(Locale, szLocaleStr, sizeof(szLocaleStr));
  49. if(lcid)
  50. {
  51. hr = GetLangStringMod(m_hMod, lcid, szThisLang, sizeof(szThisLang));
  52. if (SUCCEEDED(hr) && (lstrlenA(szThisLang) < nSize))
  53. {
  54. strcpy(szAcceptLngStr, szThisLang);
  55. szAcceptLngStr[2] = '\0';
  56. DEBUG_PRINT(DOWNLOAD,
  57. INFO,
  58. ("CLangInfo::GetAcceptLanguageString-Primary::this=%#x, szAcceptLngStr=%.10q\n",
  59. this, szAcceptLngStr
  60. ));
  61. goto Exit;
  62. }
  63. }
  64. bRetVal = FALSE;
  65. Exit:
  66. return bRetVal;
  67. }
  68. //-----------------------------------------------------------------------//
  69. BOOL CLangInfo::GetLocaleStrings(LCID Locale, char *szLocaleStr, int iLen) const
  70. {
  71. int iReturn = 0;
  72. char szBuff[50];
  73. iReturn = GetLocaleInfo(Locale, LOCALE_SABBREVLANGNAME, szBuff, sizeof(szBuff));
  74. if((!iReturn) || ((sizeof(szLocaleStr)/sizeof(szLocaleStr[0])) < iReturn))
  75. return(0);
  76. StrNCpy(szLocaleStr, szBuff, iLen);
  77. return(TRUE);
  78. }
  79. //-----------------------------------------------------------------------//
  80. LCID CLangInfo::GetPrimaryLanguageInfo(LCID Locale, char *szLocaleStr, int iLen) const
  81. {
  82. LCID lcid = NULL;
  83. int iReturn = 0;
  84. char szBuff[50];
  85. lcid = MAKELCID(MAKELANGID(PRIMARYLANGID(LANGIDFROMLCID(Locale)), SUBLANG_DEFAULT), SORT_DEFAULT);
  86. iReturn = GetLocaleInfo(lcid, LOCALE_SABBREVLANGNAME, szBuff, sizeof(szBuff));
  87. if((!iReturn) || ((sizeof(szLocaleStr)/sizeof(szLocaleStr[0])) < iReturn))
  88. return(0);
  89. StrNCpy(szLocaleStr, szBuff, iLen);
  90. return(lcid);
  91. }