-
August 25th, 2020, 01:35 AM
#1
[RESOLVED] wstring Conversion
Hi,
I was read a korean string and display the text.
Code:
std::wstring s2ws(const std::string& str)
{
int size_needed = MultiByteToWideChar(CP_UTF8, 0, &str[0], (int)str.size(), NULL, 0);
std::wstring wstrTo( size_needed, 0 );
MultiByteToWideChar(CP_UTF8, 0, &str[0], (int)str.size(), &wstrTo[0], size_needed);
//LPCWSTR result = wstrTo.c_str();
//::AfxMessageBox((CString)result);
return wstrTo;
}
void CApplicationDlg::Calling()
{
//s2ws(m_pLanguage->GetString(IDS_EXAMPLE).c_str()); //Read string from dll
s2ws("인도 남부의 맨체스터로 알려진 코임 바토르는 직물로 유명합니다.");
}
It display like wstrTo L"?? ??? ????? ??? ?? ???? ??? ?????." using watch window.
reading english, dutch, german & french characters working good.
Regards,
SaraswathiSrinath
-
August 25th, 2020, 01:48 AM
#2
Re: wstring Conversion
What language was set for non-unicode programs?
Victor Nijegorodov
-
August 25th, 2020, 01:49 AM
#3
Re: wstring Conversion
Originally Posted by VictorN
What language was set for non-unicode programs?
Sets "Use Unicode Character Set" for all string inputs
Code:
m_lblExample.SetWindowText(L"인도 남부의 맨체스터로 알려진 코임 바토르는 직물로 유명합니다.");
Its showing perfectly.
Regards,
SaraswathiSrinath
-
August 25th, 2020, 02:10 AM
#4
Re: wstring Conversion
Originally Posted by saraswathisrinath
Sets "Use Unicode Character Set" for all string inputs
Code:
m_lblExample.SetWindowText(L"인도 남부의 맨체스터로 알려진 코임 바토르는 직물로 유명합니다.");
Its showing perfectly.
Now compare it with what you showed in your OP:
Originally Posted by saraswathisrinath
Code:
...
s2ws("인도 남부의 맨체스터로 알려진 코임 바토르는 직물로 유명합니다.");
...
Victor Nijegorodov
-
August 25th, 2020, 03:21 AM
#5
Re: wstring Conversion
Originally Posted by VictorN
Now compare it with what you showed in your OP:
In the below code, watch display like ip "?? ??? ????? ??? ?? ???? ??? ?????."
Code:
std::string ip = "인도 남부의 맨체스터로 알려진 코임 바토르는 직물로 유명합니다.";
need to convert my input from const std::string str in to LPCTSTR.
This code works for English, Dutch, German & French, but not for Korean.
If i change the code for string conversion then not work for all.
Code:
void CApplicationDlg::TranslateAllControls()
{
//WORKS for all lang, not Korean
std::string ip = m_pLanguage->GetString(IDS_EXAMPLE).c_str(); //Read string from dll
std::wstring op = s2ws(ip);
LPCTSTR result=(LPCTSTR)op.c_str();
m_lblExample.SetWindowText(result);
}
Last edited by saraswathisrinath; August 25th, 2020 at 04:12 AM.
Regards,
SaraswathiSrinath
-
August 25th, 2020, 06:25 AM
#6
Re: wstring Conversion
Refered these links
https://forums.codeguru.com/showthre...em-in-VS2005-C
https://groups.google.com/g/microsof.../c/4bA_9a4U5Qw
https://www.codeproject.com/Articles...ithin-that-DLL
tried
Code:
setlocale( LC_ALL, "china");
_wsetlocale(LC_ALL, L"zh-CN");
CString buf = LoadStringFromDLL(GetModuleHandle(NULL), IDS_EXAMPLE);
m_lblExample.SetWindowText(buf);
Not working
Regards,
SaraswathiSrinath
-
August 25th, 2020, 01:31 PM
#7
Re: wstring Conversion
If you are trying to load a localized resource string from a resource library, this isnt the way to do it.
-
August 25th, 2020, 01:44 PM
#8
Re: wstring Conversion
Originally Posted by saraswathisrinath
tried
Code:
setlocale( LC_ALL, "china");
_wsetlocale(LC_ALL, L"zh-CN");
CString buf = LoadStringFromDLL(GetModuleHandle(NULL), IDS_EXAMPLE);
m_lblExample.SetWindowText(buf);
Not working
Why "china"? you wrote it is
Originally Posted by saraswathisrinath
a korean string
Victor Nijegorodov
-
August 25th, 2020, 02:08 PM
#9
Re: wstring Conversion
Originally Posted by saraswathisrinath
Hi,
I was read a korean string and display the text.
Code:
std::wstring s2ws(const std::string& str)
{
int size_needed = MultiByteToWideChar(CP_UTF8, 0, &str[0], (int)str.size(), NULL, 0);
std::wstring wstrTo( size_needed, 0 );
MultiByteToWideChar(CP_UTF8, 0, &str[0], (int)str.size(), &wstrTo[0], size_needed);
//LPCWSTR result = wstrTo.c_str();
//::AfxMessageBox((CString)result);
return wstrTo;
}
void CApplicationDlg::Calling()
{
//s2ws(m_pLanguage->GetString(IDS_EXAMPLE).c_str()); //Read string from dll
s2ws("인도 남부의 맨체스터로 알려진 코임 바토르는 직물로 유명합니다.");
}
It display like wstrTo L"?? ??? ????? ??? ?? ???? ??? ?????." using watch window.
But do you first convert this "korean string" to std::string and then try to convert it to std::wstring?
Why not to assign it to the std::wstring fro the very begin?
Victor Nijegorodov
-
August 25th, 2020, 10:46 PM
#10
Re: wstring Conversion
Originally Posted by Arjay
If you are trying to load a localized resource string from a resource library, this isnt the way to do it.
First tried like this
Code:
std::string ip = m_pLanguage->GetString(IDS_EXAMPLE).c_str();
std::wstring op = s2ws(ip);
LPCTSTR result=(LPCTSTR)op.c_str();
//::AfxMessageBox(result);
m_lblExample.SetWindowText(result);
then tried all possibilities.
Regards,
SaraswathiSrinath
-
August 25th, 2020, 10:48 PM
#11
Re: wstring Conversion
Originally Posted by VictorN
Why "china"? you wrote it is
I have created chinese.dll to read a resource string from string table like korean.
Sorry for the confusion.
Regards,
SaraswathiSrinath
-
August 25th, 2020, 11:12 PM
#12
Re: wstring Conversion
Originally Posted by VictorN
But do you first convert this "korean string" to std::string and then try to convert it to std::wstring?
Why not to assign it to the std::wstring fro the very begin?
return type is std::string, that's why assigned like below.
Code:
std::string ip = m_pLanguage->GetString(IDS_EXAMPLE).c_str();
i was converted this for display purpose
Code:
std::wstring op = s2ws(ip);
LPCTSTR result=(LPCTSTR)op.c_str();
m_lblExample.SetWindowText(result);
Regards,
SaraswathiSrinath
-
August 25th, 2020, 11:42 PM
#13
Re: wstring Conversion
Originally Posted by saraswathisrinath
First tried like this
Code:
std::string ip = m_pLanguage->GetString(IDS_EXAMPLE).c_str();
std::wstring op = s2ws(ip);
LPCTSTR result=(LPCTSTR)op.c_str();
//::AfxMessageBox(result);
m_lblExample.SetWindowText(result);
then tried all possibilities.
Have you tried the Win32 api LoadString function?
-
August 26th, 2020, 12:02 AM
#14
Re: wstring Conversion
Originally Posted by Arjay
Have you tried the Win32 api LoadString function?
Its retrive data from local resource string table.
Code:
CStringW result;
result.LoadString(IDS_EXAMPLE);
::AfxMessageBox(result);
How can i retrieve data from dll string table?
Code:
m_pLanguage->GetString(IDS_EXAMPLE)
how can i pass this in to LoadString()?
I was loaded a language DLL and extract the strings from resource table Ref: https://www.codeproject.com/Articles...93#xx5745393xx
Code:
// Init language object
CLanguage * pLanguage = CLanguage::Instance();
// Set text for static control
m_lblExample.SetWindowText(m_pLanguage->GetString(IDS_EXAMPLE).c_str());
Regards,
SaraswathiSrinath
-
August 26th, 2020, 12:15 AM
#15
Re: wstring Conversion
What is
Code:
m_pLanguage->GetString(IDS_EXAMPLE)
What class is m_pLanguage? How is its GetString method implemented?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|