I require to convert a LPCWSTR
data to wchar_t*
. I tried a bunch of methods, and some work, but when I try to get their code page, they are showing different values.
Code overview:
std::string ChineseCharacter(LPCWSTR Data) //Data value: "丂\n"
{
CString sHexValue = "";
std::wstring sData(Data);
wchar_t* str1 = (wchar_t*)Data;
//wchar_t* str2 = (wchar_t*)_wcsdup(sData.c_str());
wchar_t* str3 = (wchar_t*)(L"丂\n"); //u4E02 -- CP 8140 ** CP is needed
for (int i = 0; i < 4; i++)
{
sHexValue2.Format("%02x", str1[i]);//-- 4E02 -- FAIL
//sHexValue2.Format("%02x", str2[i]);//-- 4E02 -- FAIL
sHexValue2.Format("%02x", str3[i]);//-- First loop: 81, second one: 40 -- OK
}
}
According to the watcher, the values are:
str1= L"丂\n"
str3= L"@\n"
My doubt is, how can I pass the value of Data
to a wchar_t*
, equal as when I hard-code the value?
Reference:
https://uic.io/en/charset/show/gb18030/