Skip to content

Commit 637f8c8

Browse files
committed
The code for unicode version of project was added
1 parent f54e491 commit 637f8c8

File tree

5 files changed

+46
-11
lines changed

5 files changed

+46
-11
lines changed

projects/msvs/httpserver.v12.suo

2.5 KB
Binary file not shown.

src/Module.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11

22
#include "Module.h"
33

4-
#include <iostream>
4+
#ifdef WIN32
5+
#ifdef UNICODE
6+
#include <codecvt>
7+
#endif
8+
#endif
59

610
namespace HttpServer
711
{
@@ -55,8 +59,15 @@ namespace HttpServer
5559

5660
cookie = ::AddDllDirectory(directory.data() );
5761
}
62+
63+
#ifdef UNICODE
64+
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
65+
const std::wstring lib_path = converter.from_bytes(libPath);
66+
#else
67+
const std::string &lib_path = libPath;
68+
#endif
5869

59-
lib_handle = ::LoadLibraryEx(libPath.c_str(), 0, LOAD_LIBRARY_SEARCH_DEFAULT_DIRS);
70+
lib_handle = ::LoadLibraryEx(lib_path.c_str(), 0, LOAD_LIBRARY_SEARCH_DEFAULT_DIRS);
6071

6172
if (cookie)
6273
{

src/SignalsHandles.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include <thread>
99

1010
extern std::thread threadMessageLoop;
11-
extern char myWndClassName[];
11+
extern ::TCHAR myWndClassName[];
1212
#endif
1313

1414
int bindSignalsHandles(HttpServer::Server *server);

src/System.cpp

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@
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

1015
namespace 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
{

src/System.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#ifdef WIN32
44
#include <Windows.h>
5-
char myWndClassName[];
5+
::TCHAR myWndClassName[];
66

77
#ifdef SIGTERM
88
#undef SIGTERM

0 commit comments

Comments
 (0)