2

Please could someone explain why this does not work?

char *test = "test";
_TCHAR *szTest = CA2W(test);

And please tell me what I should be doing instead.

Instead of giving me equal text, it's giving me:

﻾﻾﻾﻾﻾﻾﻾﻾﻾﻾﻾﻾﻾﻾﻾﻾﻾﻾﻾﻾﻾﻾﻾﻾﻾﻾﻾﻾﻾﻾﻾﻾
Nick Bolton
  • 38,276
  • 70
  • 174
  • 242

1 Answers1

5

According to MSDN, that is bad. So I have used this instead:

char *test = "test";
CA2W szTest(test);

From here, we can get an LPWSTR type if we really want:

LPWSTR test = szTest.m_psz;

It also seems better to use LPWSTR instead of _TCHAR * - but I'm not sure (I think they're essentially the same thing, but could be wrong).

Nick Bolton
  • 38,276
  • 70
  • 174
  • 242
  • 1
    LPWSTR and _TCHAR* aren't always the same. W in LPWSTR tells you it's a wide string (2 bytes per character). T in _TCHAR tells you the size depends on whether you're compiling your project with unicode or multibyte character sets (in project settings), in which cases there will be 1 or 2 bytes per character depending on your build settings. – Scott Langham Dec 15 '10 at 13:29
  • You mean 1/2 bytes per code point (if indeed you have Unicode UTF-8/16 for both character types. – rubenvb Apr 14 '20 at 06:49