How to convert char* to TCHAR[ ]?

parth patel picture parth patel · May 2, 2013 · Viewed 44.8k times · Source
char*  stheParameterFileName = argv[1]; //I'm passing the file name as  a parameter.
TCHAR szName [512];

How can I convert char* to TCHAR []?

Answer

John Sibly picture John Sibly · May 2, 2013

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