Просмотр полной версии : SAMPFUNCS and encoding text
I am working on something using sampfuns and i have a function which parameters takes string example:
void CALLBACK settext(std::string params)
{
}
/settext Да
the word "Да" show in very weird characters.. can you help me to display it in correct way
itsLegend
22.07.2017, 22:50
You can check it on simple console application with multibyte encoding?
C++:
size_t
StrToWstr
(
wstring
&
aDst
,
const
string
&
aSrc
)
{
size_t length
;
length
=
mbstowcs
(
NULL
,
aSrc
.
c_str
(
)
,
0
)
;
if
(
length
!=
static_cast
(
-
1
)
)
{
wchar_t
*
buffer
=
new
wchar_t
[
length
+
1
]
;
length
=
mbstowcs
(
buffer
,
aSrc
.
c_str
(
)
,
length
)
;
buffer
[
length
]
=
L
'\0'
;
aDst
.
assign
(
buffer
)
;
delete
[
]
buffer
;
}
return
length
;
}
void
settext
(
std
::
string params
)
{
std
::
locale
::
global
(
std
::
locale
(
"Russian"
)
)
;
wstring ws
;
StrToWstr
(
ws
,
params
)
;
// ws contain correct word "Да"
char
Buff
[
512
]
;
sprintf
(
Buff
,
"%ws"
,
ws
.
c_str
(
)
)
;
// Buff is contain weird characters
}
int
main
(
)
{
settext
(
"Да"
)
;
return
0
;
}
i convert the string to widestring to be set correctly and yeah the ws contain the word without any encoding issue, but i am wondering why when i try to write it to the Buff it shows there strange characters!
Losyash1337
23.07.2017, 17:49
C++:
std
::
string str
=
"Дыа"
;
std
::
wstring wstr
(
str
.
begin
(
)
,
str
.
end
(
)
)
;
// cpp style
C++:
// Windows style
char
*
a
=
"Дыа"
;
wchar_t
*
b
=
new
wchar_t
[
10
]
;
CharToOem
(
a
,
b
)
;
// CHAR* to WCHAR*
OemToChar
(
b
,
a
)
;
// WCHAR* to CHAR*
thank you so much! it works ;)
vBulletin® v3.8.14, Copyright ©2000-2026, vBulletin Solutions, Inc. Перевод: zCarot