How to convert char* to TCHAR[ ]?

c++, tchar, visual-studio-2012, winapi

Solution

If you include the header file:

#include "atlstr.h"

Then you can use the A2T macro as below:

// You'd need this line if using earlier versions of ATL/Visual Studio
// USES_CONVERSION;

char*  stheParameterFileName = argv[1];
TCHAR szName [512];
_tcscpy(szName, A2T(stheParameterFileName));
MessageBox(NULL, szName, szName, MB_OK);

Details on MSDN

Problem

``` char* stheParameterFileName = argv[1]; //I'm passing the file name as a parameter. TCHAR szName [512]; ``` How can I convert `char*` to `TCHAR []`?

Original source

Related problems