Source code of Windows XP (NT5)
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.

120 lines
2.2 KiB

  1. #ifndef _WB_UTILS_H_
  2. #define _WB_UTILS_H_
  3. #include "excption.h"
  4. #include "regkey.h"
  5. inline WCHAR* CreateFilePath(const WCHAR* pwcsFile)
  6. {
  7. HMODULE h;
  8. h = GetModuleHandle(L"LangWrbk.dll");
  9. if (NULL == h)
  10. {
  11. THROW_WIN32ERROR_EXCEPTION(GetLastError());
  12. }
  13. CAutoArrayPointer<WCHAR> apwcsPath;
  14. ULONG ulInitSize = 128;
  15. ULONG ulPathLen;
  16. do
  17. {
  18. ulInitSize *= 2;
  19. apwcsPath = new WCHAR[ulInitSize + wcslen(pwcsFile) + 1];
  20. ulPathLen = GetModuleFileName(
  21. h,
  22. apwcsPath.Get(),
  23. ulInitSize);
  24. } while (ulPathLen >= ulInitSize);
  25. if (0 == ulPathLen)
  26. {
  27. THROW_WIN32ERROR_EXCEPTION(GetLastError());
  28. }
  29. while ((ulPathLen > 0) &&
  30. (apwcsPath.Get()[ulPathLen - 1] != L'\\'))
  31. {
  32. ulPathLen--;
  33. }
  34. apwcsPath.Get()[ulPathLen] = L'\0';
  35. wcscat(apwcsPath.Get(), pwcsFile);
  36. return apwcsPath.Detach();
  37. }
  38. class CWbToUpper
  39. {
  40. public:
  41. CWbToUpper();
  42. //
  43. // SOME ACCESS FUNCTIONS:
  44. //
  45. __forceinline
  46. static
  47. WCHAR
  48. MapToUpper(
  49. IN WCHAR wc
  50. )
  51. {
  52. extern CWbToUpper g_WbToUpper;
  53. if (wc < 0x100)
  54. {
  55. return g_WbToUpper.m_pwcsCaseMapTable[wc];
  56. }
  57. else
  58. {
  59. WCHAR wchOut;
  60. LCMapString(
  61. LOCALE_NEUTRAL,
  62. LCMAP_UPPERCASE,
  63. &wc,
  64. 1,
  65. &wchOut,
  66. 1 );
  67. return wchOut;
  68. }
  69. }
  70. public:
  71. WCHAR m_pwcsCaseMapTable[0x100];
  72. }; // CFE_CWbToUpper
  73. extern CWbToUpper g_WbToUpper;
  74. inline CWbToUpper::CWbToUpper( )
  75. {
  76. //
  77. // the code use to use LCMapString (with LANG_NEUTRAL) to initialize the UPPER array.
  78. // LCMapString behaves weirdly on Greek WIN98 (possibly a bug)
  79. //
  80. for (WCHAR wch = 0; wch <= 0xFF; wch++)
  81. {
  82. m_pwcsCaseMapTable[wch] = wch;
  83. }
  84. for (WCHAR wch = 0x61; wch <= 0x7A; wch++)
  85. {
  86. m_pwcsCaseMapTable[wch] = wch - 0x20;
  87. }
  88. for (WCHAR wch = 0xE0; wch <= 0xFE; wch++)
  89. {
  90. m_pwcsCaseMapTable[wch] = wch - 0x20;
  91. }
  92. }
  93. #endif // _WB_UTILS_H_