BaseFun.cpp 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #include "stdafx.h"
  2. #include "BaseFun.h"
  3. #include "array.h"
  4. #ifdef RVC_OS_WIN
  5. #include <ShlDisp.h>
  6. #include <direct.h>
  7. #include <io.h>
  8. #include <string.h>
  9. #else
  10. #include <sys/types.h>
  11. #include <sys/stat.h>
  12. #include <unistd.h>
  13. #endif // RVC_OS_WIN
  14. #ifndef RVC_MAX_INI_LEN
  15. #define RVC_MAX_INI_LEN 1024*16
  16. #endif // !RVC_MAX_INI_LEN
  17. void StringToWstring(std::wstring& szDst, std::string str)
  18. {
  19. #ifdef RVC_OS_WIN
  20. std::string temp = str;
  21. int len = MultiByteToWideChar(CP_ACP, 0, (LPCSTR)temp.c_str(), -1, NULL, 0);
  22. wchar_t* wszUtf8 = new wchar_t[len + 1];
  23. memset(wszUtf8, 0, len * 2 + 2);
  24. MultiByteToWideChar(CP_ACP, 0, (LPCSTR)temp.c_str(), -1, (LPWSTR)wszUtf8, len);
  25. szDst = wszUtf8;
  26. std::wstring r = wszUtf8;
  27. delete[] wszUtf8;
  28. #else
  29. setlocale(LC_ALL, "chs");
  30. const char* _Source = str.c_str();
  31. size_t _Dsize = str.size() + 1;
  32. wchar_t* _Dest = new wchar_t[_Dsize];
  33. wmemset(_Dest, 0, _Dsize);
  34. mbstowcs(_Dest, _Source, _Dsize);
  35. std::wstring result = _Dest;
  36. delete[]_Dest;
  37. setlocale(LC_ALL, "C");
  38. szDst = result;
  39. #endif
  40. }