refactor: switch to wide string

This commit is contained in:
k0t9i
2023-01-25 19:53:02 +04:00
parent f7198a13ef
commit eb7bfc779b
46 changed files with 284 additions and 293 deletions

View File

@@ -18,15 +18,15 @@ public:
return true;
}
const void Send(const std::string& data) override
const void Send(const std::wstring& data) override
{
OutputDebugStringA(data.c_str());
OutputDebugStringW(data.c_str());
}
const std::string Receive() override
const std::wstring Receive() override
{
// delay imitation
std::this_thread::sleep_for(std::chrono::milliseconds(50));
return "";
return L"";
}
DebugViewTransport() = default;

View File

@@ -10,7 +10,7 @@
class NamedPipe
{
public:
const bool Connect(const std::string& pipeName)
const bool Connect(const std::wstring& pipeName)
{
if (m_Pipe == NULL || m_PipeName != pipeName)
{
@@ -25,7 +25,7 @@ public:
CreateOverlapped(m_WritingOverlapped);
}
m_Pipe = CreateNamedPipeA(("\\\\.\\pipe\\" + pipeName).c_str(),
m_Pipe = CreateNamedPipeW((L"\\\\.\\pipe\\" + pipeName).c_str(),
PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED,
PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT,
PIPE_UNLIMITED_INSTANCES,
@@ -58,7 +58,7 @@ public:
return m_Connected;
}
void Send(const std::string& message)
void Send(const std::wstring& message)
{
if (!m_Connected)
{
@@ -66,7 +66,7 @@ public:
}
DWORD written;
const auto result = WriteFile(m_Pipe, message.c_str(), message.size() + 1, &written, &m_WritingOverlapped);
const auto result = WriteFile(m_Pipe, message.c_str(), (message.size() + 1) * sizeof(wchar_t), &written, &m_WritingOverlapped);
const auto lastError = GetLastError();
if (!result)
@@ -88,16 +88,16 @@ public:
}
}
const std::string Receive()
const std::wstring Receive()
{
if (!m_Connected)
{
return "";
return L"";
}
DWORD dwRead;
std::unique_ptr<char[]> buffer = std::make_unique<char[]>(BUFFER_SIZE);
const auto result = ReadFile(m_Pipe, buffer.get(), BUFFER_SIZE * sizeof(char), &dwRead, &m_ReadingOverlapped);
std::unique_ptr<wchar_t[]> buffer = std::make_unique<wchar_t[]>(BUFFER_SIZE);
const auto result = ReadFile(m_Pipe, buffer.get(), BUFFER_SIZE * sizeof(wchar_t), &dwRead, &m_ReadingOverlapped);
const auto lastError = GetLastError();
if (!result)
@@ -110,17 +110,17 @@ public:
if (!overlappedResult)
{
m_Connected = false;
return "";
return L"";
}
}
else
{
m_Connected = false;
return "";
return L"";
}
}
std::string message = std::string(buffer.get());
std::wstring message = std::wstring(buffer.get());
return message;
}
@@ -182,7 +182,7 @@ private:
}
private:
std::string m_PipeName = "";
std::wstring m_PipeName = L"";
HANDLE m_Pipe = NULL;
bool m_Connected = false;
OVERLAPPED m_ConntectingOverlapped = OVERLAPPED();

View File

@@ -11,7 +11,7 @@ class NamedPipeTransport : public Transports::TransportInterface
public:
const bool Connect() override
{
OutputDebugStringA(m_PipeName.c_str());
OutputDebugStringW(m_PipeName.c_str());
if (!m_ConnectionPipe.Connect(m_PipeName))
{
return false;
@@ -19,9 +19,9 @@ public:
OutputDebugStringA("Client connected to connection pipe");
const std::string mainPipeName = GenerateUUID();
const auto mainPipeName = GenerateUUID();
m_ConnectionPipe.Send("\\\\.\\pipe\\" + mainPipeName);
m_ConnectionPipe.Send(L"\\\\.\\pipe\\" + mainPipeName);
OutputDebugStringA("Name of main pipe sended");
@@ -32,12 +32,12 @@ public:
}
OutputDebugStringA("Client connected to main pipe");
m_Pipe.Send("Hello!");
m_Pipe.Send(L"Hello!");
return true;
}
const void Send(const std::string& data) override
const void Send(const std::wstring& data) override
{
if (!m_Pipe.IsConnected())
{
@@ -46,11 +46,11 @@ public:
m_Pipe.Send(data);
}
const std::string Receive() override
const std::wstring Receive() override
{
if (!m_Pipe.IsConnected())
{
return "";
return L"";
}
return m_Pipe.Receive();
@@ -61,7 +61,7 @@ public:
return m_Pipe.IsConnected();
}
NamedPipeTransport(const std::string& pipeName) :
NamedPipeTransport(const std::wstring& pipeName) :
m_PipeName(pipeName)
{
}
@@ -72,5 +72,5 @@ public:
private:
NamedPipe m_ConnectionPipe;
NamedPipe m_Pipe;
std::string m_PipeName = "";
std::wstring m_PipeName = L"";
};