ANTICHAT

ANTICHAT (https://forum.antichat.xyz/index.php)
-   С/С++, C#, Rust, Swift, Go, Java, Perl, Ruby (https://forum.antichat.xyz/forumdisplay.php?f=24)
-   -   SAMPFUNCS and encoding text (https://forum.antichat.xyz/showthread.php?t=1317740)

seek1 22.07.2017 22:40

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?

seek1 23.07.2017 15:40

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*


seek1 28.07.2017 01:12

thank you so much! it works ;)


Время: 16:10