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.

149 lines
3.3 KiB

  1. /*************************************************************************
  2. *
  3. * WIDE.C
  4. *
  5. * Wide character translation routines
  6. *
  7. * Copyright (c) 1995 Microsoft Corporation
  8. *
  9. * $Log: N:\NT\PRIVATE\NW4\NWSCRIPT\VCS\WIDE.C $
  10. *
  11. * Rev 1.2 10 Apr 1996 14:24:14 terryt
  12. * Hotfix for 21181hq
  13. *
  14. * Rev 1.2 12 Mar 1996 19:56:36 terryt
  15. * Relative NDS names and merge
  16. *
  17. * Rev 1.1 22 Dec 1995 14:27:18 terryt
  18. * Add Microsoft headers
  19. *
  20. * Rev 1.0 15 Nov 1995 18:08:20 terryt
  21. * Initial revision.
  22. *
  23. * Rev 1.1 23 May 1995 19:37:32 terryt
  24. * Spruce up source
  25. *
  26. * Rev 1.0 15 May 1995 19:11:14 terryt
  27. * Initial revision.
  28. *
  29. *************************************************************************/
  30. #include <stdio.h>
  31. #include <direct.h>
  32. #include <time.h>
  33. #include <stdlib.h>
  34. #include <nt.h>
  35. #include <ntrtl.h>
  36. #include <nturtl.h>
  37. #include <windows.h>
  38. #include "nwscript.h"
  39. /********************************************************************
  40. szToWide
  41. Routine Description:
  42. Given a single byte character string, convert to wide
  43. Arguments:
  44. lpszW - Wide character string returned
  45. lpszC - Single character string input
  46. nSize - length of Wide character buffer
  47. Return Value:
  48. 0 = success
  49. else NT error
  50. *******************************************************************/
  51. DWORD
  52. szToWide(
  53. LPWSTR lpszW,
  54. LPCSTR lpszC,
  55. INT nSize
  56. )
  57. {
  58. if (!MultiByteToWideChar(CP_OEMCP,
  59. MB_PRECOMPOSED,
  60. lpszC,
  61. -1,
  62. lpszW,
  63. nSize))
  64. {
  65. return (GetLastError()) ;
  66. }
  67. return NO_ERROR ;
  68. }
  69. /********************************************************************
  70. WideTosz
  71. Routine Description:
  72. Given a wide character string, convert to single
  73. Arguments:
  74. lpszC - Single character string returned
  75. lpszW - Wide character string input
  76. nSize - length of single character buffer
  77. Return Value:
  78. 0 = success
  79. else NT error
  80. *******************************************************************/
  81. DWORD
  82. WideTosz(
  83. LPSTR lpszC,
  84. LPWSTR lpszW,
  85. INT nSize
  86. )
  87. {
  88. if (!WideCharToMultiByte(CP_OEMCP,
  89. 0,
  90. (LPCWSTR) lpszW,
  91. -1,
  92. lpszC,
  93. nSize,
  94. NULL,
  95. NULL))
  96. {
  97. return (GetLastError()) ;
  98. }
  99. return NO_ERROR ;
  100. }
  101. /********************************************************************
  102. ConvertUnicodeToAscii
  103. Routine Description:
  104. Given a wide character string, convert to single
  105. Arguments:
  106. Buffer - buffer to be converted
  107. Return Value:
  108. none
  109. *******************************************************************/
  110. void
  111. ConvertUnicodeToAscii( PVOID Buffer )
  112. {
  113. LPCWSTR lpszW = Buffer;
  114. BYTE Destination[1024];
  115. WideTosz( (LPSTR)Destination, (LPWSTR)Buffer, 1024 );
  116. strcpy( Buffer, Destination );
  117. }