1

Topic: WideCharToMultiByte with CP_UTF8 returns a line in the unknown coding (

Good afternoon.
On one of machines, with Win7 Pro the Russian.

std:: string WideToMultiByte (uint32_t dst_encoding, const std::wstring& str) {
int ret = WideCharToMultiByte (static_cast <UINT> (dst_encoding), 0, str.c_str (), str.size (), NULL, 0, NULL, NULL);
if (0 == ret) ThrowWin32Exception (L "WideCharToMultiByte step1");
std:: unique_ptr <CHAR> buf (new CHAR [ret]);
ret = WideCharToMultiByte (static_cast <UINT> (dst_encoding), 0, str.c_str (), str.size (), buf.get (), ret, NULL, NULL);
if (0 == ret) ThrowWin32Exception (L "WideCharToMultiByte step2");
return std:: string (buf.get (), ret);
}
auto result = WideToMultiByte (CP_UTF8, L "FELIX-R ");

result contains a line in not clear coding (contents attached in a file).
And if to fulfill

auto result = WideToMultiByte (1251, L "FELIX-R ");

That on an output I receive utf8 the text.
How such can be? What with it to do?)

2

Re: WideCharToMultiByte with CP_UTF8 returns a line in the unknown coding (

What result will be if  a line from an example with the help
StringToUtf8A
From here
http://www.sql.ru/forum/actualutils.asp … g=20637426

3

Re: WideCharToMultiByte with CP_UTF8 returns a line in the unknown coding (

chikanok wrote:

and if to fulfill

auto result = WideToMultiByte (1251, L "FELIX-R ");

That on an output I receive...

What is 1251?
Esteem the documentation on function WideCharToMultiByte
There is not present any 1251

4

Re: WideCharToMultiByte with CP_UTF8 returns a line in the unknown coding (

chikanok wrote:

As such can be?

Very simply: at you garbage on an input, and at all that you think. Literals not so are simple
As it seems.

5

Re: WideCharToMultiByte with CP_UTF8 returns a line in the unknown coding (

Cerebrum wrote:

there is not present any 1251

Lie - code page number (in   1251) or one of constants CP_xxx

6

Re: WideCharToMultiByte with CP_UTF8 returns a line in the unknown coding (

wrote:

it is passed...
Lie - code page number (in   1251) or one of constants CP_xxx

It agree, here I am not right

7

Re: WideCharToMultiByte with CP_UTF8 returns a line in the unknown coding (

Cerebrum wrote:

What result will be if  a line from an example with the help
StringToUtf8A
From here
http://www.sql.ru/forum/actualutils.asp … g=20637426

c StringToUtf8W on an output too most.

8

Re: WideCharToMultiByte with CP_UTF8 returns a line in the unknown coding (

chikanok wrote:

it is passed...
c StringToUtf8W on an output too most.

The coding 1251 not the coding installed by default means by the machine.
Come into adjustments  and forcedly  Russian .
If does not help, check up that at you in the register in branch NLS (the screenshot see)

9

Re: WideCharToMultiByte with CP_UTF8 returns a line in the unknown coding (

All thanks!
The problem dared parameter adding/source-charset:utf-8 in compiler command line.

10

Re: WideCharToMultiByte with CP_UTF8 returns a line in the unknown coding (

In that that source codes in utf8 and the compiler them read similar essence as 1251.

11

Re: WideCharToMultiByte with CP_UTF8 returns a line in the unknown coding (

"Mi you ..." ()