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.

70 lines
1.8 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1998 - 1999
  6. //
  7. // File: charconv.cxx
  8. //
  9. //--------------------------------------------------------------------------
  10. #include <precomp.hxx>
  11. #include "Charconv.hxx"
  12. RPC_STATUS A2WAttachHelper(char *pszAnsi, WCHAR **ppUnicode)
  13. {
  14. int nAnsiLength;
  15. ASSERT(pszAnsi != NULL);
  16. nAnsiLength = lstrlenA(pszAnsi) + 1;
  17. *ppUnicode = new WCHAR[nAnsiLength];
  18. if (*ppUnicode == NULL)
  19. return(RPC_S_OUT_OF_MEMORY);
  20. RtlMultiByteToUnicodeN(*ppUnicode, nAnsiLength * 2, NULL, pszAnsi, nAnsiLength);
  21. return(RPC_S_OK);
  22. }
  23. RPC_STATUS W2AAttachHelper(WCHAR *pUnicode, char **ppAnsi)
  24. {
  25. int nUnicodeLength;
  26. ASSERT(pUnicode != NULL);
  27. NTSTATUS status;
  28. status = RtlUnicodeToMultiByteSize((unsigned long *)&nUnicodeLength,
  29. pUnicode, lstrlenW(pUnicode) * 2);
  30. if (status)
  31. return RPC_S_INVALID_ARG;
  32. nUnicodeLength ++;
  33. *ppAnsi = new char[nUnicodeLength];
  34. if (*ppAnsi == NULL)
  35. return(RPC_S_OUT_OF_MEMORY);
  36. RtlUnicodeToMultiByteN(*ppAnsi, nUnicodeLength, NULL, pUnicode, nUnicodeLength * 2);
  37. return(RPC_S_OK);
  38. }
  39. RPC_STATUS CHeapUnicode::Attach(char *pszAnsi)
  40. {
  41. ANSI_STRING AnsiString;
  42. NTSTATUS NtStatus;
  43. RtlInitAnsiString(&AnsiString, (PSZ)pszAnsi);
  44. NtStatus = RtlAnsiStringToUnicodeString(&m_UnicodeString, &AnsiString, TRUE);
  45. if (!NT_SUCCESS(NtStatus))
  46. return(RPC_S_OUT_OF_MEMORY);
  47. return(RPC_S_OK);
  48. }
  49. RPC_STATUS CHeapAnsi::Attach(WCHAR *pszUnicode)
  50. {
  51. UNICODE_STRING UnicodeString;
  52. NTSTATUS NtStatus;
  53. RtlInitUnicodeString(&UnicodeString, pszUnicode);
  54. NtStatus = RtlUnicodeStringToAnsiString(&m_AnsiString, &UnicodeString, TRUE);
  55. if (!NT_SUCCESS(NtStatus))
  56. return(RPC_S_OUT_OF_MEMORY);
  57. return(RPC_S_OK);
  58. }