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.

44 lines
693 B

  1. #pragma once
  2. //---------------------------------------------------------------------------
  3. // CStringUTF8
  4. //---------------------------------------------------------------------------
  5. class CStringUTF8
  6. {
  7. public:
  8. CStringUTF8(LPCWSTR pszOld) :
  9. m_pchNew(NULL)
  10. {
  11. if (pszOld)
  12. {
  13. int cchNew = WideCharToMultiByte(CP_UTF8, 0, pszOld, -1, NULL, 0, NULL, NULL);
  14. m_pchNew = new CHAR[cchNew];
  15. if (m_pchNew)
  16. {
  17. WideCharToMultiByte(CP_UTF8, 0, pszOld, -1, m_pchNew, cchNew, NULL, NULL);
  18. }
  19. }
  20. }
  21. ~CStringUTF8()
  22. {
  23. delete [] m_pchNew;
  24. }
  25. operator LPCSTR()
  26. {
  27. return m_pchNew;
  28. }
  29. protected:
  30. LPSTR m_pchNew;
  31. };
  32. #define WTUTF8(s) static_cast<LPCSTR>(CStringUTF8(s))