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.

106 lines
2.1 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. umlib.c
  5. Abstract:
  6. This string handling the UM 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. #if defined(DEVSTUDIO)
  16. #include "..\precomp.h"
  17. #else
  18. #include "precomp.h"
  19. #endif
  20. DWORD
  21. DwCopyStringToUnicodeString(
  22. IN UINT uiCodePage,
  23. IN PSTR pstrCharIn,
  24. OUT PWSTR pwstrCharOut,
  25. IN INT iwcOutSize)
  26. {
  27. INT iCharCountIn;
  28. INT iRetVal;
  29. size_t stStringLength;
  30. if ( NULL == pwstrCharOut )
  31. {
  32. return (DWORD)-1;
  33. }
  34. iCharCountIn = strlen(pstrCharIn) + 1;
  35. iRetVal = MultiByteToWideChar( uiCodePage,
  36. 0,
  37. pstrCharIn,
  38. iCharCountIn,
  39. pwstrCharOut,
  40. iwcOutSize);
  41. if ( 0 == iRetVal ||
  42. FAILED ( StringCchLengthW ( pwstrCharOut, iwcOutSize, &stStringLength ) ) )
  43. {
  44. pwstrCharOut[iwcOutSize-1] = TEXT('\0');
  45. }
  46. return (DWORD)iRetVal;
  47. }
  48. DWORD
  49. DwCopyUnicodeStringToString(
  50. IN UINT uiCodePage,
  51. IN PWSTR pwstrCharIn,
  52. OUT PSTR pstrCharOut,
  53. IN INT icbOutSize)
  54. {
  55. INT iCharCountIn;
  56. INT iRetVal;
  57. size_t stStringLength;
  58. if ( NULL == pstrCharOut )
  59. {
  60. return (DWORD)-1;
  61. }
  62. iCharCountIn = wcslen(pwstrCharIn) + 1;
  63. iRetVal = WideCharToMultiByte( uiCodePage,
  64. 0,
  65. pwstrCharIn,
  66. iCharCountIn,
  67. pstrCharOut,
  68. icbOutSize,
  69. NULL,
  70. NULL);
  71. if ( 0 == iRetVal ||
  72. FAILED ( StringCchLengthA ( pstrCharOut, icbOutSize, &stStringLength ) ) )
  73. {
  74. pstrCharOut[icbOutSize-1] = '\0';
  75. }
  76. return (DWORD)iRetVal;
  77. }