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.

98 lines
2.0 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. unilib.c
  5. Abstract:
  6. This string handling the KM code for Unidrv
  7. Environment:
  8. Win32 subsystem, Unidrv driver
  9. Revision History:
  10. 11/12/96 -eigos-
  11. Created it.
  12. dd-mm-yy -author-
  13. description
  14. --*/
  15. #include "precomp.h"
  16. DWORD
  17. DwCopyStringToUnicodeString(
  18. IN UINT uiCodePage,
  19. IN PSTR pstrCharIn,
  20. OUT PWSTR pwstrCharOut,
  21. IN INT iwcOutSize)
  22. {
  23. INT iCharCountIn;
  24. INT iRetVal;
  25. size_t stStringLength;
  26. if ( NULL == pwstrCharOut )
  27. {
  28. return (DWORD)(-1);
  29. }
  30. iCharCountIn = strlen(pstrCharIn) + 1;
  31. iRetVal = EngMultiByteToWideChar(uiCodePage,
  32. pwstrCharOut,
  33. iwcOutSize * sizeof(WCHAR),
  34. pstrCharIn,
  35. iCharCountIn);
  36. if ( -1 == iRetVal ||
  37. FAILED ( StringCchLengthW ( pwstrCharOut, iwcOutSize, &stStringLength ) ) )
  38. {
  39. pwstrCharOut[iwcOutSize-1] = TEXT('\0');
  40. }
  41. return (DWORD)iRetVal;
  42. }
  43. DWORD
  44. DwCopyUnicodeStringToString(
  45. IN UINT uiCodePage,
  46. IN PWSTR pwstrCharIn,
  47. OUT PSTR pstrCharOut,
  48. IN INT icbOutSize)
  49. {
  50. INT iCharCountIn;
  51. INT iRetVal;
  52. size_t stStringLength;
  53. if ( NULL == pstrCharOut )
  54. {
  55. return (DWORD)(-1);
  56. }
  57. iCharCountIn = wcslen(pwstrCharIn) + 1;
  58. iRetVal = EngWideCharToMultiByte(uiCodePage,
  59. pwstrCharIn,
  60. iCharCountIn * sizeof(WCHAR),
  61. pstrCharOut,
  62. icbOutSize);
  63. if ( -1 == iRetVal ||
  64. FAILED ( StringCchLengthA ( pstrCharOut, icbOutSize, &stStringLength ) ) )
  65. {
  66. pstrCharOut[icbOutSize-1] = '\0';
  67. }
  68. return (DWORD)iRetVal;
  69. }