Home > Archive > VC STL > August 2005 > What is the most elegant way to convert string from unicode to ANSI?
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
What is the most elegant way to convert string from unicode to ANSI?
|
|
|
| Hi, again.
I set my project UNICODE, and use TCHAR, wstring, and so on.
But, some legacy api need ANSI, so I use WideCharToMultiByte(CP_ACP, ...)
If I want to use it properly, I should call this method twice to know exact
way for char* and
dynamic allocation and Whew...
Do you have any elegant and beautiful way to convert wstring (or
CStringT<wchar_t> or wchar_t) to char ?
Thanks in advance.
| |
| Alex Blekhman 2005-08-17, 4:09 am |
| P wrote:
> Hi, again.
> I set my project UNICODE, and use TCHAR, wstring, and so
> on.
> But, some legacy api need ANSI, so I use
> WideCharToMultiByte(CP_ACP, ...)
>
> If I want to use it properly, I should call this method
> twice to know exact way for char* and
> dynamic allocation and Whew...
>
> Do you have any elegant and beautiful way to convert
> wstring (or CStringT<wchar_t> or wchar_t) to char ?
You have following options:
1. _bstr_t class. Requires compiler COM support classes.
2. "ATL and MFC String Conversion Macros" - look im MSDN for
article with that name. Obviously requires MFC/ATL.
3. Write your own function.
| |
|
|
|
| Thanks both of you.
Your advice helps me a lot!
"Ajay Kalra" <ajaykalra@yahoo.com> wrote in message
news:1124292752.222701.257960@g44g2000cwa.googlegroups.com...
> Look at macros W2A, W2CA etc. Technical Note 59 will be helpful as
> well:
>
> http://msdn.microsoft.com/library/d...notes_tn059.asp
>
> --------
> Ajay Kalra
> ajaykalra@yahoo.com
>
|
|
|
|
|