1
0

AutoWide.h 613 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #ifndef AUTOWIDEH
  2. #define AUTOWIDEH
  3. class AutoWide
  4. {
  5. public:
  6. AutoWide(const char *convert) : allocated(false), wide(0)
  7. {
  8. // review maybe CP_UTF8?
  9. int size = MultiByteToWideChar(CP_ACP, 0, convert, -1, 0,0);
  10. if (!size)
  11. return;
  12. wide = new unsigned short[size];
  13. allocated=true;
  14. if (!MultiByteToWideChar(CP_ACP, 0, convert, -1, wide,size))
  15. {
  16. delete wide;
  17. wide=0;
  18. allocated=false;
  19. }
  20. }
  21. ~AutoWide()
  22. {
  23. if (allocated)
  24. {
  25. delete wide;
  26. wide=0;
  27. allocated=false;
  28. }
  29. }
  30. operator unsigned short *()
  31. {
  32. return wide;
  33. }
  34. private:
  35. bool allocated;
  36. unsigned short *wide;
  37. };
  38. #endif