CString conversion problem
-
Hi, i m reading value from ini file and reading into CString.values are stored in japanese language in ini file.now when i convert CString into WCHAR it turns into garbage value.any solution?
-
Hi, i m reading value from ini file and reading into CString.values are stored in japanese language in ini file.now when i convert CString into WCHAR it turns into garbage value.any solution?
How are you converting?
-
How are you converting?
CString name; WCHAR disname[100]={0}; name= m_IniReader.getKeyValue(str,"VIEWNAME");; wcscpy(disname, A2W((LPCSTR)name)); like this?
-
CString name; WCHAR disname[100]={0}; name= m_IniReader.getKeyValue(str,"VIEWNAME");; wcscpy(disname, A2W((LPCSTR)name)); like this?
Try this :)
WCHAR disname\[100\]={0}; CStringW name; name= m\_IniReader.getKeyValue(str,"VIEWNAME"); wcscpy(disname, (LPCWSTR)name.GetBuffer(100)); MessageBoxW(NULL,disname,disname,MB\_OK); name.ReleaseBuffer(100);
-
Try this :)
WCHAR disname\[100\]={0}; CStringW name; name= m\_IniReader.getKeyValue(str,"VIEWNAME"); wcscpy(disname, (LPCWSTR)name.GetBuffer(100)); MessageBoxW(NULL,disname,disname,MB\_OK); name.ReleaseBuffer(100);
Mohan Ramachandra wrote:
wcscpy(disname, (LPCWSTR)name.GetBuffer(100));
No, calling GetBuffer is really a very bad practice. You shouldn't do that, the CString class already provides cast operators so there's no need to call GetBuffer ! And the the case is probably no needed neither, but that depends how the project was compiled (UNICODE or not).
Cédric Moonen Software developer
Charting control [v3.0] OpenGL game tutorial in C++ -
CString name; WCHAR disname[100]={0}; name= m_IniReader.getKeyValue(str,"VIEWNAME");; wcscpy(disname, A2W((LPCSTR)name)); like this?
I suggest you read this excellent article[^]. You'll understand much more about string manipulation afterward.
Cédric Moonen Software developer
Charting control [v3.0] OpenGL game tutorial in C++ -
Mohan Ramachandra wrote:
wcscpy(disname, (LPCWSTR)name.GetBuffer(100));
No, calling GetBuffer is really a very bad practice. You shouldn't do that, the CString class already provides cast operators so there's no need to call GetBuffer ! And the the case is probably no needed neither, but that depends how the project was compiled (UNICODE or not).
Cédric Moonen Software developer
Charting control [v3.0] OpenGL game tutorial in C++ -
CString name; WCHAR disname[100]={0}; name= m_IniReader.getKeyValue(str,"VIEWNAME");; wcscpy(disname, A2W((LPCSTR)name)); like this?
Did u check the whether you are getting the japanese text in CString? And i hope its a UNICODE build.
Величие не Бога может быть недооценена.
-
GetBuffer
(as the name suggests) exposes the internal buffer of theCString
object. Moreover you must remember to callReleaseBuffer
when you've done with it. Most of the times, you really don't need to call it. :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
Because if you read the documentation of the function, you will see that you get a pointer to the internal buffer of the string and that you HAVE to call ReleaseBuffer afterward (which will be often forgotten). Furthermore, why would you use GetBuffer, while the CString provides a cast operator which returns you the same thing ? Calling GetBuffer can lead to mistakes if you forget to call ReleaseBuffer.
Cédric Moonen Software developer
Charting control [v3.0] OpenGL game tutorial in C++ -
Did u check the whether you are getting the japanese text in CString? And i hope its a UNICODE build.
Величие не Бога может быть недооценена.
yes i m getting japanese text in CString.
-
Mohan Ramachandra wrote:
wcscpy(disname, (LPCWSTR)name.GetBuffer(100));
No, calling GetBuffer is really a very bad practice. You shouldn't do that, the CString class already provides cast operators so there's no need to call GetBuffer ! And the the case is probably no needed neither, but that depends how the project was compiled (UNICODE or not).
Cédric Moonen Software developer
Charting control [v3.0] OpenGL game tutorial in C++Cedric Moonen wrote:
No, calling GetBuffer is really a very bad practice. You shouldn't do that, the CString class already provides cast operators so there's no need to call GetBuffer !
Thanks, I didn't know that
-
yes i m getting japanese text in CString.
Please check whether _UNICODE preprocessor is added in your project setting.
Величие не Бога может быть недооценена.
-
CString name; WCHAR disname[100]={0}; name= m_IniReader.getKeyValue(str,"VIEWNAME");; wcscpy(disname, A2W((LPCSTR)name)); like this?
CString name; WCHAR disname[100]={0}; name= m_IniReader.getKeyValue(str,"VIEWNAME");; wcscpy(disname, A2W((LPCWSTR)name)); Use this code. And make sure that your project build support UNICODE.
Raj Jaiswal