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.

48 lines
1.0 KiB

  1. // Copyright (c) 1995 Microsoft Corporation. All Rights Reserved.
  2. //
  3. // CMultiByteStr
  4. //
  5. // Quick and dirty converter from TSTR to WSTR.
  6. // note that in the UNICODE case no copy is performed,
  7. // so the lifetime of the string pointed to must be longer
  8. // than this object.
  9. class CMultiByteStr {
  10. public:
  11. CMultiByteStr(LPCTSTR szString) {
  12. #ifdef UNICODE
  13. m_wszString = szString;
  14. #else
  15. int iLen = MultiByteToWideChar(CP_ACP, 0,
  16. szString, -1,
  17. m_wszString, 0);
  18. m_wszString = new WCHAR[iLen];
  19. if (m_wszString == NULL) {
  20. throw CHRESULTException(E_OUTOFMEMORY);
  21. }
  22. MultiByteToWideChar(CP_ACP, 0,
  23. szString, -1,
  24. m_wszString, iLen);
  25. #endif
  26. }
  27. ~CMultiByteStr() {
  28. #ifndef UNICODE
  29. delete[] m_wszString;
  30. #endif
  31. }
  32. operator LPCWSTR() { return m_wszString; }
  33. private:
  34. #ifdef UNICODE
  35. LPCWSTR m_wszString; // const if UNICODE
  36. #else
  37. LPWSTR m_wszString;
  38. #endif
  39. };