I asked a similar question before. But I am still in trouble with encodings in c++. I try to describe the problem as well as possible.
I have a c++ client, communicating with an c# service over TCP. Now I need to display the Messages from the service in an Messagebox (Win32 API). The Bytes, sended by the c# service are UTF-8 encoded.
Important to know, the c++ client will only be running on Windows Systems.
This is the code to receive the bytes and to display the Text:
char buffer[1024];
int receivedBytes = recv(socketHandle, buffer, sizeof(buffer) - 1, 0);
char str[receivedBytes];
for (int index = 0; index < receivedBytes; index++)
{
str[index] = buffer[index];
}
MessageBox(mainWindow, (LPCTSTR)str, (LPCTSTR) "Fehler", MB_OK|MB_ICONERROR);
If the Text contains chatacters like üäö, they are not shown in the Messagebox the correct way. What can I do to receive the message as UTF-8 String in c++? Is there a possibility to convert the char[] to an UTF-8 String?
Thx for helping
Tobi
resultanywhere?buffer[receivedBytes] = 0;. Apart from that, it's better to usememcpyfor that purpose than copy byte by byte in a loop.