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.

64 lines
1.4 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 2000.
  5. //
  6. // File: U S T R I N G 2 . C P P
  7. //
  8. // Contents: Simple string class
  9. //
  10. // Notes:
  11. //
  12. // Author: mbend 17 Aug 2000
  13. //
  14. //----------------------------------------------------------------------------
  15. #include <pch.h>
  16. #pragma hdrstop
  17. #include "UString.h"
  18. #include "ComUtility.h"
  19. HRESULT CUString::HrGetBSTR(BSTR * pbstr) const
  20. {
  21. CHECK_POINTER(pbstr);
  22. HRESULT hr = S_OK;
  23. *pbstr = SysAllocString(m_sz ? m_sz : L"");
  24. if(!*pbstr)
  25. {
  26. hr = E_OUTOFMEMORY;
  27. }
  28. TraceHr(ttidError, FAL, hr, FALSE, "CUString::GetBSTR");
  29. return hr;
  30. }
  31. HRESULT CUString::HrGetCOM(wchar_t ** psz) const
  32. {
  33. CHECK_POINTER(psz);
  34. HRESULT hr = S_OK;
  35. *psz = reinterpret_cast<wchar_t*>(CoTaskMemAlloc((GetLength() + 1) * sizeof(wchar_t)));
  36. if(*psz)
  37. {
  38. lstrcpy(*psz, m_sz ? m_sz: L"\0");
  39. }
  40. else
  41. {
  42. hr = E_OUTOFMEMORY;
  43. }
  44. TraceHr(ttidError, FAL, hr, FALSE, "CUString::GetCOM");
  45. return hr;
  46. }
  47. HRESULT CUString::HrInitFromGUID(const GUID & guid)
  48. {
  49. HRESULT hr = S_OK;
  50. Clear();
  51. const int c_cchGuidWithTerm = 39; // includes terminating null
  52. wchar_t szGUID[c_cchGuidWithTerm];
  53. StringFromGUID2(guid, szGUID, c_cchGuidWithTerm);
  54. hr = HrAssign(szGUID);
  55. TraceHr(ttidError, FAL, hr, FALSE, "CUString::HrInitFromGUID");
  56. return hr;
  57. }