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.

197 lines
5.1 KiB

  1. /*++
  2. Copyright (c) 1998 Microsoft Corporation
  3. Module Name:
  4. unicode.h
  5. Abstract:
  6. Declares the interfaces for unicode/ansi conversion.
  7. When specific conversion is needed, use:
  8. unicode = ConvertAtoW (ansi) / FreeConvertedStr (unicode)
  9. ansi = ConvertWtoA (unicode) / FreeConvertedStr (ansi)
  10. KnownSizeAtoW (unicode,ansi)
  11. KnownSizeWtoA (ansi,unicode)
  12. When TCHAR conversion is needed, use:
  13. ansi = CreateDbcs (tchar) / DestroyDbcs (ansi)
  14. unicode = CreateUnicode (tchar) / DestroyUnicode (unicode)
  15. tchar = ConvertAtoT (ansi) / FreeAtoT (tchar)
  16. tchar = ConvertWtoT (ansi) / FreeWtoT (tchar)
  17. Author:
  18. Jim Schmidt (jimschm) 02-Sep-1997
  19. Revision History:
  20. jimschm 15-Feb-1999 Eliminated AnsiFromUnicode and UnicodeFromAnsi
  21. calinn 07-Jul-1998 SetGlobalPage/GetGlobalPage
  22. mikeco 03-Nov-1997 AnsiFromUnicode/UnicodeFromAnsi
  23. --*/
  24. #pragma once
  25. extern WORD g_GlobalCodePage;
  26. #define OurGetACP() (g_GlobalCodePage)
  27. VOID
  28. SetGlobalCodePage (
  29. IN WORD CodePage,
  30. IN LCID Locale
  31. );
  32. VOID
  33. GetGlobalCodePage (
  34. OUT PWORD CodePage, OPTIONAL
  35. OUT PLCID Locale OPTIONAL
  36. );
  37. #define INVALID_CHAR_COUNT 0xffffffff
  38. //
  39. // Explicit conversions, pool-based, unlimited size
  40. //
  41. PCSTR
  42. RealUnicodeToDbcsN (
  43. IN POOLHANDLE Pool, OPTIONAL
  44. IN PCWSTR StrIn,
  45. IN DWORD Chars
  46. );
  47. PCWSTR
  48. RealDbcsToUnicodeN (
  49. IN POOLHANDLE Pool, OPTIONAL
  50. IN PCSTR StrIn,
  51. IN DWORD Chars
  52. );
  53. #define UnicodeToDbcsN(p,s,c) SETTRACKCOMMENT(PCSTR,"UnicodeToDbcsN",__FILE__,__LINE__)\
  54. RealUnicodeToDbcsN(p,s,c)\
  55. CLRTRACKCOMMENT
  56. #define DbcsToUnicodeN(p,s,c) SETTRACKCOMMENT(PCWSTR,"DbcsToUnicodeN",__FILE__,__LINE__)\
  57. RealDbcsToUnicodeN(p,s,c)\
  58. CLRTRACKCOMMENT
  59. #define UnicodeToDbcs(pool,str) UnicodeToDbcsN(pool,str,wcslen(str))
  60. #define DbcsToUnicode(pool,str) DbcsToUnicodeN(pool,str,CharCountA(str))
  61. #define ConvertWtoA(unicode_str) UnicodeToDbcsN(NULL,unicode_str,wcslen(unicode_str))
  62. #define ConvertAtoW(dbcs_str) DbcsToUnicodeN(NULL,dbcs_str,CharCountA(dbcs_str))
  63. VOID
  64. FreeConvertedPoolStr (
  65. IN POOLHANDLE Pool, OPTIONAL
  66. IN PVOID StrIn
  67. );
  68. #define FreeConvertedStr(str) FreeConvertedPoolStr(NULL,(PVOID)(str))
  69. //
  70. // In-place explicit conversions, caller handles buffer sizing
  71. //
  72. PSTR
  73. KnownSizeUnicodeToDbcsN (
  74. OUT PSTR StrOut,
  75. IN PCWSTR StrIn,
  76. IN DWORD CharCount
  77. );
  78. PWSTR
  79. KnownSizeDbcsToUnicodeN (
  80. OUT PWSTR StrOut,
  81. IN PCSTR StrIn,
  82. IN DWORD CharCount
  83. );
  84. #define KnownSizeUnicodeToDbcs(out,in) KnownSizeUnicodeToDbcsN(out,in,INVALID_CHAR_COUNT)
  85. #define KnownSizeDbcsToUnicode(out,in) KnownSizeDbcsToUnicodeN(out,in,INVALID_CHAR_COUNT)
  86. #define KnownSizeWtoA KnownSizeUnicodeToDbcs
  87. #define KnownSizeAtoW KnownSizeDbcsToUnicode
  88. PSTR
  89. DirectUnicodeToDbcsN (
  90. OUT PSTR StrOut,
  91. IN PCWSTR StrIn,
  92. IN DWORD Bytes
  93. );
  94. PWSTR
  95. DirectDbcsToUnicodeN (
  96. OUT PWSTR StrOut,
  97. IN PCSTR StrIn,
  98. IN DWORD Bytes
  99. );
  100. #define DirectUnicodeToDbcs(out,in) DirectUnicodeToDbcsN(out,in,INVALID_CHAR_COUNT)
  101. #define DirectDbcsToUnicode(out,in) DirectDbcsToUnicodeN(out,in,INVALID_CHAR_COUNT)
  102. #define DirectWtoA DirectUnicodeToDbcs
  103. #define DirectAtoW DirectDbcsToUnicode
  104. //
  105. // TCHAR conversions -- do not call A & W versions directly
  106. //
  107. #define CreateDbcsW(unicode_str) ConvertWtoA(unicode_str)
  108. #define DestroyDbcsW(unicode_str) FreeConvertedStr(unicode_str)
  109. #define CreateUnicodeW(unicode_str) (unicode_str)
  110. #define DestroyUnicodeW(unicode_str)
  111. #define CreateDbcsA(dbcs_str) (dbcs_str)
  112. #define DestroyDbcsA(dbcs_str)
  113. #define CreateUnicodeA(dbcs_str) ConvertAtoW(dbcs_str)
  114. #define DestroyUnicodeA(dbcs_str) FreeConvertedStr(dbcs_str)
  115. #ifdef UNICODE
  116. #define CreateDbcs CreateDbcsW
  117. #define CreateUnicode CreateUnicodeW
  118. #define DestroyDbcs DestroyDbcsW
  119. #define DestroyUnicode DestroyUnicodeW
  120. #define ConvertAtoT ConvertAtoW
  121. #define ConvertWtoT(x) (x)
  122. #define FreeAtoT FreeConvertedStr
  123. #define FreeWtoT(x)
  124. #define KnownSizeAtoT KnownSizeAtoW
  125. #define KnownSizeWtoT(out,in) (in)
  126. #define DirectAtoT DirectAtoW
  127. #define DirectWtoT(out,in) (in)
  128. #else
  129. #define CreateDbcs CreateDbcsA
  130. #define CreateUnicode CreateUnicodeA
  131. #define DestroyDbcs DestroyDbcsA
  132. #define DestroyUnicode DestroyUnicodeA
  133. #define ConvertAtoT(x) (x)
  134. #define ConvertWtoT ConvertWtoA
  135. #define FreeAtoT(x)
  136. #define FreeWtoT FreeConvertedStr
  137. #define KnownSizeAtoT(out,in) (in)
  138. #define KnownSizeWtoT KnownSizeWtoA
  139. #define DirectAtoT(out,in) (in)
  140. #define DirectWtoT DirectWtoA
  141. #endif