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.

91 lines
1.8 KiB

  1. /*++
  2. Copyright (c) 1990-2000 Microsoft Corporation
  3. Module Name:
  4. wtoa.c
  5. Abstract:
  6. This module provides all the public exported APIs relating to Printer
  7. and Job management for the Local Print Providor
  8. --*/
  9. #include <stdio.h>
  10. #include <windows.h>
  11. #include <string.h>
  12. #include <rpc.h>
  13. #include "winspl.h"
  14. #include <offsets.h>
  15. #define NULL_TERMINATED 0
  16. /* AnsiToUnicodeString
  17. *
  18. * Parameters:
  19. *
  20. * pAnsi - A valid source ANSI string.
  21. *
  22. * pUnicode - A pointer to a buffer large enough to accommodate
  23. * the converted string.
  24. *
  25. * StringLength - The length of the source ANSI string.
  26. * If 0 (NULL_TERMINATED), the string is assumed to be
  27. * null-terminated.
  28. *
  29. * Return:
  30. *
  31. * The return value from MultiByteToWideChar, the number of
  32. * wide characters returned.
  33. *
  34. *
  35. * andrewbe, 11 Jan 1993
  36. */
  37. INT AnsiToUnicodeString( LPSTR pAnsi, LPWSTR pUnicode, DWORD StringLength )
  38. {
  39. if( StringLength == NULL_TERMINATED )
  40. StringLength = strlen( pAnsi );
  41. return MultiByteToWideChar( CP_ACP,
  42. MB_PRECOMPOSED,
  43. pAnsi,
  44. StringLength + 1,
  45. pUnicode,
  46. StringLength + 1 );
  47. }
  48. LPWSTR
  49. AllocateUnicodeString(
  50. LPSTR pPrinterName
  51. )
  52. {
  53. LPWSTR pUnicodeString;
  54. if (!pPrinterName)
  55. return NULL;
  56. pUnicodeString = LocalAlloc(LPTR, strlen(pPrinterName)*sizeof(WCHAR) +
  57. sizeof(WCHAR));
  58. if (pUnicodeString)
  59. AnsiToUnicodeString(pPrinterName, pUnicodeString, NULL_TERMINATED);
  60. return pUnicodeString;
  61. }
  62. LPWSTR
  63. FreeUnicodeString(
  64. LPWSTR pUnicodeString
  65. )
  66. {
  67. if (!pUnicodeString)
  68. return NULL;
  69. return LocalFree(pUnicodeString);
  70. }
  71.