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.

161 lines
5.9 KiB

  1. // --------------------------------------------------------------------------
  2. // Module Name: StringConvert.cpp
  3. //
  4. // Copyright (c) 1999, Microsoft Corporation
  5. //
  6. // Utility string functions. These are probably duplicated in some form in
  7. // shlwapi.dll. Currently this file exists to prevent some dependencies on
  8. // that file.
  9. //
  10. // History: 1999-08-23 vtan created
  11. // 1999-11-16 vtan separate file
  12. // 2000-01-31 vtan moved from Neptune to Whistler
  13. // --------------------------------------------------------------------------
  14. #include "StandardHeader.h"
  15. #include "StringConvert.h"
  16. // --------------------------------------------------------------------------
  17. // CStringConvert::AnsiToUnicode
  18. //
  19. // Arguments: pszAnsiString = ANSI string to convert.
  20. // pszUnicodeString = UNICODE string receiving output.
  21. // iUnicodeStringCount = Character count of output string.
  22. //
  23. // Returns: int = See kernel32!MultiByteToWideChar.
  24. //
  25. // Purpose: Explicitly converts an ANSI string to a UNICODE string.
  26. //
  27. // History: 1999-08-23 vtan created
  28. // --------------------------------------------------------------------------
  29. int CStringConvert::AnsiToUnicode (const char *pszAnsiString, WCHAR *pszUnicodeString, int iUnicodeStringCount)
  30. {
  31. return(MultiByteToWideChar(CP_ACP, 0, pszAnsiString, -1, pszUnicodeString, iUnicodeStringCount));
  32. }
  33. // --------------------------------------------------------------------------
  34. // CStringConvert::UnicodeToAnsi
  35. //
  36. // Arguments: pszUnicodeString = UNICODE string receiving output.
  37. // pszAnsiString = ANSI string to convert.
  38. // iAnsiStringCount = Character count of output string.
  39. //
  40. // Returns: int = See kernel32!WideCharToMultiByte.
  41. //
  42. // Purpose: Explicitly converts a UNICODE string to an ANSI string.
  43. //
  44. // History: 1999-08-23 vtan created
  45. // --------------------------------------------------------------------------
  46. int CStringConvert::UnicodeToAnsi (const WCHAR *pszUnicodeString, char *pszAnsiString, int iAnsiStringCount)
  47. {
  48. return(WideCharToMultiByte(CP_ACP, 0, pszUnicodeString, -1, pszAnsiString, iAnsiStringCount, NULL, NULL));
  49. }
  50. // --------------------------------------------------------------------------
  51. // CStringConvert::TCharToUnicode
  52. //
  53. // Arguments: pszString = TCHAR string to convert.
  54. // pszUnicodeString = UNICODE string receiving output.
  55. // iUnicodeStringCount = Character count of output string.
  56. //
  57. // Returns: <none>
  58. //
  59. // Purpose: Converts a TCHAR string to a UNICODE string. The actual
  60. // implementation depends on whether the is being compiled
  61. // UNICODE or ANSI.
  62. //
  63. // History: 1999-08-23 vtan created
  64. // --------------------------------------------------------------------------
  65. void CStringConvert::TCharToUnicode (const TCHAR *pszString, WCHAR *pszUnicodeString, int iUnicodeStringCount)
  66. {
  67. #ifdef UNICODE
  68. (const char*)lstrcpyn(pszUnicodeString, pszString, iUnicodeStringCount);
  69. #else
  70. (int)AnsiToUnicode(pszString, pszUnicodeString, iUnicodeStringCount);
  71. #endif
  72. }
  73. // --------------------------------------------------------------------------
  74. // CStringConvert::UnicodeToTChar
  75. //
  76. // Arguments: pszUnicodeString = UNICODE string to convert.
  77. // pszString = TCHAR string receiving output.
  78. // iStringCount = Character count of output string.
  79. //
  80. // Returns: <none>
  81. //
  82. // Purpose: Converts a TCHAR string to a ANSI string. The actual
  83. // implementation depends on whether the is being compiled
  84. // UNICODE or ANSI.
  85. //
  86. // History: 1999-08-23 vtan created
  87. // --------------------------------------------------------------------------
  88. void CStringConvert::UnicodeToTChar (const WCHAR *pszUnicodeString, TCHAR *pszString, int iStringCount)
  89. {
  90. #ifdef UNICODE
  91. (const char*)lstrcpyn(pszString, pszUnicodeString, iStringCount);
  92. #else
  93. (int)UnicodeToAnsi(pszUnicodeString, pszString, iStringCount);
  94. #endif
  95. }
  96. // --------------------------------------------------------------------------
  97. // CStringConvert::TCharToAnsi
  98. //
  99. // Arguments: pszString = TCHAR string to convert.
  100. // pszAnsiString = ANSI string receiving output.
  101. // iAnsiStringCount = Character count of output string.
  102. //
  103. // Returns: <none>
  104. //
  105. // Purpose: Converts a TCHAR string to a ANSI string. The actual
  106. // implementation depends on whether the is being compiled
  107. // UNICODE or ANSI.
  108. //
  109. // History: 1999-08-23 vtan created
  110. // --------------------------------------------------------------------------
  111. void CStringConvert::TCharToAnsi (const TCHAR *pszString, char *pszAnsiString, int iAnsiStringCount)
  112. {
  113. #ifdef UNICODE
  114. (int)UnicodeToAnsi(pszString, pszAnsiString, iAnsiStringCount);
  115. #else
  116. (const char*)lstrcpyn(pszAnsiString, pszString, iAnsiStringCount);
  117. #endif
  118. }
  119. // --------------------------------------------------------------------------
  120. // CStringConvert::AnsiToTChar
  121. //
  122. // Arguments: pszAnsiString = ANSI string to convert.
  123. // pszString = TCHAR string receiving output.
  124. // iStringCount = Character count of output string.
  125. //
  126. // Returns: <none>
  127. //
  128. // Purpose: Converts a TCHAR string to a ANSI string. The actual
  129. // implementation depends on whether the is being compiled
  130. // UNICODE or ANSI.
  131. //
  132. // History: 1999-08-23 vtan created
  133. // --------------------------------------------------------------------------
  134. void CStringConvert::AnsiToTChar (const char *pszAnsiString, TCHAR *pszString, int iStringCount)
  135. {
  136. #ifdef UNICODE
  137. (int)AnsiToUnicode(pszAnsiString, pszString, iStringCount);
  138. #else
  139. (const char*)lstrcpyn(pszString, pszAnsiString, iStringCount);
  140. #endif
  141. }