44#include < array>
55
66#ifdef WIN32
7- char myWndClassName[] = " WndClassNameConstant" ;
7+ #include < tchar.h>
8+ ::TCHAR myWndClassName[] = TEXT(" WndClassNameConstant" );
9+
10+ #ifdef UNICODE
11+ #include < codecvt>
12+ #endif
813#endif
914
1015namespace System
@@ -26,11 +31,11 @@ namespace System
2631
2732 if (process_id == ed.process_id && ::GetConsoleWindow () != hWnd)
2833 {
29- std::array<char , 65 > class_name;
34+ std::array<::TCHAR, 257 > class_name;
3035
3136 ::GetClassName (hWnd, class_name.data(), class_name.size() - 1);
3237
33- if (0 == ::strcmp (class_name.data (), myWndClassName) )
38+ if (0 == ::_tcscmp (class_name.data (), myWndClassName) )
3439 {
3540 ed.hWnd = hWnd;
3641
@@ -65,11 +70,16 @@ namespace System
6570 std::string getTempDir ()
6671 {
6772 #ifdef WIN32
68- std::array<std::string::value_type , MAX_PATH + 1 > buf;
73+ std::array<TCHAR , MAX_PATH + 1 > buf;
6974
7075 const size_t len = ::GetTempPath (buf.size (), buf.data () );
7176
72- return std::string (buf.cbegin (), buf.cbegin () + len);
77+ #ifdef UNICODE
78+ std::wstring_convert<std::codecvt_utf8_utf16<wchar_t >> converter;
79+ return converter.to_bytes (buf.data () );
80+ #else
81+ return std::string (buf.cbegin (), buf.cbegin () + len);
82+ #endif
7383 #elif POSIX
7484 const char *buf = ::getenv (" TMPDIR" );
7585
@@ -94,7 +104,14 @@ namespace System
94104 bool isFileExists (const std::string &fileName)
95105 {
96106 #ifdef WIN32
97- const ::DWORD attrib = ::GetFileAttributes (fileName.c_str () );
107+ #ifdef UNICODE
108+ std::wstring_convert<std::codecvt_utf8_utf16<wchar_t >> converter;
109+ const std::wstring file_name = converter.from_bytes (fileName);
110+ #else
111+ const std::string &file_name = fileName;
112+ #endif
113+
114+ const ::DWORD attrib = ::GetFileAttributes (file_name.c_str () );
98115
99116 if (INVALID_FILE_ATTRIBUTES == attrib)
100117 {
@@ -119,7 +136,14 @@ namespace System
119136 bool getFileSizeAndTimeGmt (const std::string &filePath, size_t *fileSize, time_t *fileTime)
120137 {
121138 #ifdef WIN32
122- ::HANDLE hFile = ::CreateFile (filePath.c_str (), GENERIC_READ, FILE_SHARE_READ, nullptr , OPEN_EXISTING, 0 , nullptr );
139+ #ifdef UNICODE
140+ std::wstring_convert<std::codecvt_utf8_utf16<wchar_t >> converter;
141+ const std::wstring file_path = converter.from_bytes (filePath);
142+ #else
143+ const std::string &file_path = filePath;
144+ #endif
145+
146+ ::HANDLE hFile = ::CreateFile (file_path.c_str (), GENERIC_READ, FILE_SHARE_READ, nullptr , OPEN_EXISTING, 0 , nullptr );
123147
124148 if (INVALID_HANDLE_VALUE == hFile)
125149 {
0 commit comments