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.

175 lines
3.4 KiB

  1. /*++
  2. Copyright (c) 1998-2000 Microsoft Corporation
  3. Module Name:
  4. w32utl.cpp
  5. Abstract:
  6. Win32-Specific Utilities for the RDP Client Device Redirector
  7. Author:
  8. Tad Brockway
  9. Revision History:
  10. --*/
  11. #include <precom.h>
  12. #define TRC_FILE "w32utl"
  13. #include "w32utl.h"
  14. #include "atrcapi.h"
  15. #include "drdbg.h"
  16. ULONG
  17. RDPConvertToAnsi(
  18. LPWSTR lpwszUnicodeString,
  19. LPSTR lpszAnsiString,
  20. ULONG ulAnsiBufferLen
  21. )
  22. /*++
  23. Routine Description:
  24. Converts a Ansi string to Unicode.
  25. Arguments:
  26. lpwszUnicodeString - pointer to a unicode string to convert.
  27. lpszAnsiString - pointer to a ansi string buffer.
  28. ulAnsiBufferLen - Ansi buffer length.
  29. Return Value:
  30. Windows Error Code.
  31. --*/
  32. {
  33. ULONG ulRetVal;
  34. ULONG ulUnicodeStrLen;
  35. int count;
  36. DC_BEGIN_FN("RDPConvertToAnsi");
  37. ulUnicodeStrLen = wcslen(lpwszUnicodeString);
  38. if( ulUnicodeStrLen != 0 ) {
  39. count =
  40. WideCharToMultiByte(
  41. CP_ACP,
  42. WC_COMPOSITECHECK | WC_DEFAULTCHAR,
  43. lpwszUnicodeString,
  44. -1,
  45. lpszAnsiString,
  46. ulAnsiBufferLen,
  47. NULL, // system default character.
  48. NULL); // no notification of conversion failure.
  49. if (count == 0) {
  50. ulRetVal = GetLastError();
  51. TRC_ERR((TB, _T("RDPConvertToAnsi WideCharToMultiByte %ld."),ulRetVal));
  52. }
  53. else {
  54. ulRetVal = ERROR_SUCCESS;
  55. }
  56. }
  57. else {
  58. if (ulAnsiBufferLen > 0) {
  59. ulRetVal = ERROR_SUCCESS;
  60. lpszAnsiString[0] = '\0';
  61. }
  62. else {
  63. ulRetVal = ERROR_INSUFFICIENT_BUFFER;
  64. ASSERT(FALSE);
  65. }
  66. }
  67. DC_END_FN();
  68. return ulRetVal;
  69. }
  70. ULONG
  71. RDPConvertToUnicode(
  72. LPSTR lpszAnsiString,
  73. LPWSTR lpwszUnicodeString,
  74. ULONG ulUnicodeBufferLen
  75. )
  76. /*++
  77. Routine Description:
  78. Converts a Ansi string to Unicode.
  79. Arguments:
  80. lpszAnsiString - pointer to a ansi string to convert.
  81. lpwszUnicodeString - pointer to a unicode buffer.
  82. ulUnicodeBufferLen - unicode buffer length.
  83. Return Value:
  84. Windows Error Code.
  85. --*/
  86. {
  87. ULONG ulRetVal;
  88. ULONG ulAnsiStrLen;
  89. int count;
  90. DC_BEGIN_FN("RDPConvertToUnicode");
  91. ulAnsiStrLen = strlen(lpszAnsiString);
  92. if( ulAnsiStrLen != 0 ) {
  93. //
  94. // Wide char string is terminated
  95. // by MultiByteToWideChar
  96. //
  97. count =
  98. MultiByteToWideChar(
  99. CP_ACP,
  100. MB_PRECOMPOSED,
  101. lpszAnsiString,
  102. -1,
  103. lpwszUnicodeString,
  104. ulUnicodeBufferLen);
  105. if (count == 0) {
  106. ulRetVal = GetLastError();
  107. TRC_ERR((TB, _T("RDPConvertToUnicode MultiByteToWideChar %ld."),ulRetVal));
  108. }
  109. else {
  110. ulRetVal = ERROR_SUCCESS;
  111. }
  112. }
  113. else {
  114. //
  115. // do nothing.
  116. //
  117. if (ulUnicodeBufferLen > 0) {
  118. ulRetVal = ERROR_SUCCESS;
  119. lpwszUnicodeString[0] = L'\0';
  120. }
  121. else {
  122. ulRetVal = ERROR_INSUFFICIENT_BUFFER;
  123. ASSERT(FALSE);
  124. }
  125. }
  126. DC_END_FN();
  127. return ulRetVal;
  128. }