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.

255 lines
6.9 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. See macros at the end of this file for details! (Search for ***)
  8. Author:
  9. Jim Schmidt (jimschm) 02-Sep-1997
  10. Revision History:
  11. jimschm 16-Mar-2000 PTSTR<->PCSTR/PCWSTR routines
  12. jimschm 15-Feb-1999 Eliminated AnsiFromUnicode and UnicodeFromAnsi
  13. calinn 07-Jul-1998 SetGlobalPage/GetGlobalPage
  14. mikeco 03-Nov-1997 AnsiFromUnicode/UnicodeFromAnsi
  15. --*/
  16. #pragma once
  17. extern WORD g_GlobalCodePage;
  18. #define OurGetACP() (g_GlobalCodePage)
  19. VOID
  20. SetGlobalCodePage (
  21. IN WORD CodePage,
  22. IN LCID Locale
  23. );
  24. VOID
  25. GetGlobalCodePage (
  26. OUT PWORD CodePage, OPTIONAL
  27. OUT PLCID Locale OPTIONAL
  28. );
  29. WORD
  30. SetConversionCodePage (
  31. IN WORD CodePage
  32. );
  33. #define INVALID_CHAR_COUNT 0xffffffff
  34. //
  35. // Explicit conversions, pool-based, unlimited size
  36. //
  37. PCSTR
  38. RealUnicodeToDbcsN (
  39. IN PMHANDLE Pool, OPTIONAL
  40. IN PCWSTR StrIn,
  41. IN DWORD Chars
  42. );
  43. PCWSTR
  44. RealDbcsToUnicodeN (
  45. IN PMHANDLE Pool, OPTIONAL
  46. IN PCSTR StrIn,
  47. IN DWORD Chars
  48. );
  49. #define UnicodeToDbcsN(p,s,c) TRACK_BEGIN(PCSTR, UnicodeToDbcsN)\
  50. RealUnicodeToDbcsN(p,s,c)\
  51. TRACK_END()
  52. #define DbcsToUnicodeN(p,s,c) TRACK_BEGIN(PCWSTR, DbcsToUnicodeN)\
  53. RealDbcsToUnicodeN(p,s,c)\
  54. TRACK_END()
  55. #define UnicodeToDbcs(pool,str) UnicodeToDbcsN(pool,str,(DWORD)wcslen(str))
  56. #define DbcsToUnicode(pool,str) DbcsToUnicodeN(pool,str,CharCountA(str))
  57. #define ConvertWtoA(unicode_str) UnicodeToDbcsN(NULL,unicode_str,(DWORD)wcslen(unicode_str))
  58. #define ConvertAtoW(dbcs_str) DbcsToUnicodeN(NULL,dbcs_str,CharCountA(dbcs_str))
  59. VOID
  60. FreeConvertedPoolStr (
  61. IN PMHANDLE Pool, OPTIONAL
  62. IN PVOID StrIn
  63. );
  64. #define FreeConvertedStr(str) FreeConvertedPoolStr(NULL,(PVOID)(str))
  65. //
  66. // In-place explicit conversions, caller handles buffer sizing
  67. //
  68. PSTR
  69. KnownSizeUnicodeToDbcsN (
  70. OUT PSTR StrOut,
  71. IN PCWSTR StrIn,
  72. IN DWORD CharCount
  73. );
  74. PWSTR
  75. KnownSizeDbcsToUnicodeN (
  76. OUT PWSTR StrOut,
  77. IN PCSTR StrIn,
  78. IN DWORD CharCount
  79. );
  80. #define KnownSizeUnicodeToDbcs(out,in) KnownSizeUnicodeToDbcsN(out,in,INVALID_CHAR_COUNT)
  81. #define KnownSizeDbcsToUnicode(out,in) KnownSizeDbcsToUnicodeN(out,in,INVALID_CHAR_COUNT)
  82. #define KnownSizeWtoA KnownSizeUnicodeToDbcs
  83. #define KnownSizeAtoW KnownSizeDbcsToUnicode
  84. #define MaxSizeUnicodeToDbcs(out,in,c) KnownSizeUnicodeToDbcsN(out,in,min(c,CharCountW(in)))
  85. #define MaxSizeDbcsToUnicode(out,in,c) KnownSizeDbcsToUnicodeN(out,in,min(c,CharCountA(in)))
  86. PSTR
  87. DirectUnicodeToDbcsN (
  88. OUT PSTR StrOut,
  89. IN PCWSTR StrIn,
  90. IN DWORD Bytes
  91. );
  92. PWSTR
  93. DirectDbcsToUnicodeN (
  94. OUT PWSTR StrOut,
  95. IN PCSTR StrIn,
  96. IN DWORD Bytes
  97. );
  98. #define DirectUnicodeToDbcs(out,in) DirectUnicodeToDbcsN(out,in,INVALID_CHAR_COUNT)
  99. #define DirectDbcsToUnicode(out,in) DirectDbcsToUnicodeN(out,in,INVALID_CHAR_COUNT)
  100. #define DirectWtoA DirectUnicodeToDbcs
  101. #define DirectAtoW DirectDbcsToUnicode
  102. //
  103. // TCHAR conversions -- do not call A & W versions directly
  104. //
  105. #define CreateDbcsW(unicode_str) ConvertWtoA(unicode_str)
  106. #define DestroyDbcsW(unicode_str) FreeConvertedStr(unicode_str)
  107. #define CreateUnicodeW(unicode_str) (unicode_str)
  108. #define DestroyUnicodeW(unicode_str)
  109. #define CreateDbcsA(dbcs_str) (dbcs_str)
  110. #define DestroyDbcsA(dbcs_str)
  111. #define CreateUnicodeA(dbcs_str) ConvertAtoW(dbcs_str)
  112. #define DestroyUnicodeA(dbcs_str) FreeConvertedStr(dbcs_str)
  113. #define DuplicateDbcsW(unicode_str) ((PSTR) ConvertWtoA(unicode_str))
  114. #define FreeDuplicatedDbcsW(unicode_str) FreeConvertedStr(unicode_str)
  115. #define DuplicateUnicodeW(unicode_str) ((PWSTR) DuplicateTextW(unicode_str))
  116. #define FreeDuplicatedUnicodeW(unicode_str) FreeTextW(unicode_str)
  117. #define DuplicateDbcsA(dbcs_str) ((PSTR) DuplicateTextA(dbcs_str))
  118. #define FreeDuplicatedDbcsA(dbcs_str) FreeTextA(dbcs_str)
  119. #define DuplicateUnicodeA(dbcs_str) ((PWSTR) ConvertAtoW(dbcs_str))
  120. #define FreeDuplicatedUnicodeA(dbcs_str) FreeConvertedStr(dbcs_str)
  121. //
  122. // **********************************************************************
  123. //
  124. // - Call ConvertWtoA or ConvertAtoW for PCSTR<->PCWSTR conversion,
  125. // FreeConvertedStr to clean up
  126. //
  127. // - Call KnownSizeAtoW or KnownSizeWtoA for PCSTR<->PCWSTR conversion
  128. // when you know the destination can hold the result
  129. //
  130. // - Call the routines below for TCHAR<->dbcs/unicode conversion
  131. //
  132. // **********************************************************************
  133. //
  134. #ifdef UNICODE
  135. //
  136. // If your string is a PCTSTR, use these routines:
  137. //
  138. #define CreateDbcs CreateDbcsW
  139. #define CreateUnicode CreateUnicodeW
  140. #define DestroyDbcs DestroyDbcsW
  141. #define DestroyUnicode DestroyUnicodeW
  142. //
  143. // If your string is a PTSTR, use these routines:
  144. //
  145. #define DuplicateDbcs DuplicateDbcsW
  146. #define DuplicateUnicode DuplicateUnicodeW
  147. #define FreeDuplicatedDbcs FreeDuplicatedDbcsW
  148. #define FreeDuplicatedUnicode FreeDuplicatedUnicodeW
  149. //
  150. // If your string is a PCSTR or PCWSTR, use these routines:
  151. //
  152. #define ConvertAtoT ConvertAtoW
  153. #define ConvertWtoT(x) (x)
  154. #define FreeAtoT FreeConvertedStr
  155. #define FreeWtoT(x)
  156. // Known size means you know the out buffer is big enough!
  157. #define KnownSizeAtoT KnownSizeAtoW
  158. #define KnownSizeWtoT(out,in) (in)
  159. // These are low-level routines that don't care about nuls:
  160. #define DirectAtoT DirectAtoW
  161. #define DirectWtoT(out,in) (in)
  162. #else
  163. //
  164. // If your string is a PCTSTR, use these routines:
  165. //
  166. #define CreateDbcs CreateDbcsA
  167. #define CreateUnicode CreateUnicodeA
  168. #define DestroyDbcs DestroyDbcsA
  169. #define DestroyUnicode DestroyUnicodeA
  170. //
  171. // If your string is a PCSTR or PCWSTR, use these routines:
  172. //
  173. #define ConvertAtoT(x) (x)
  174. #define ConvertWtoT ConvertWtoA
  175. #define FreeAtoT(x)
  176. #define FreeWtoT FreeConvertedStr
  177. //
  178. // If your string is a PTSTR, use these routines:
  179. //
  180. #define DuplicateDbcs DuplicateDbcsA
  181. #define DuplicateUnicode DuplicateUnicodeA
  182. #define FreeDuplicatedDbcs FreeDuplicatedDbcsA
  183. #define FreeDuplicatedUnicode FreeDuplicatedUnicodeA
  184. // Known size means you know the out buffer is big enough!
  185. #define KnownSizeAtoT(out,in) (in)
  186. #define KnownSizeWtoT KnownSizeWtoA
  187. // These are low-level routines that don't care about nuls:
  188. #define DirectAtoT(out,in) (in)
  189. #define DirectWtoT DirectWtoA
  190. #endif