Share via


How to convert unsigned short* to wchar_t*

Question

Friday, April 10, 2009 2:51 PM

How to convert unsigned short* to wchar_t*

All replies (3)

Friday, April 10, 2009 3:03 PM âś…Answered

I would first ask you why you want to do this. In VC6, wchar_t was just a typedef for unsigned short. In more recent versions, wchar_t is a distinct type, but the old behavior is available as an option.

If the compiler is complaining about this, perhaps you are trying to link components using different wchar_t settings.

That said, C-style cast or reinterpret_cast should work (I think), because wchar_t is two bytes in VC.David Wilkinson | Visual C++ MVP


Friday, April 10, 2009 3:15 PM

I need to concatenate the strings that are obtained in unsigned short*. These strings may contain two-byte characters as well.
I tried following but it doesn't work

const wchar_t* newword = reinterpret_cast<wchar_t*>(oldword); // here oldword is of type unsigned short*


Friday, April 10, 2009 3:20 PM

Why do you have the strings in unsigned short* in the first place?

And what "doesn't work"?

Also, didn't you mean

const wchar_t* newword = reinterpret_cast<const wchar_t*>(oldword);David Wilkinson | Visual C++ MVP