c 2b 2b convert const char 2a to lpcwstr

Solutions on MaxInterview for c 2b 2b convert const char 2a to lpcwstr by the best coders in the world

showing results for - "c 2b 2b convert const char 2a to lpcwstr"
Ahmed
06 Feb 2020
1  const char *p = "D:\\";
2  const WCHAR *pwcsName; //LPCWSTR
3  
4  // required size
5  int size = MultiByteToWideChar(CP_ACP, 0, p, -1, NULL, 0);
6  // allocate it
7  pwcsName = new WCHAR[nChars];
8  MultiByteToWideChar(CP_ACP, 0, p, -1, (LPWSTR)pwcsName, size);
9  // use it....
10    
11  // delete it
12  delete [] pwcsName;
13}