One of the problems that often comes up in Windows programming is the conversion between strings, and the development process always encounters the problem that the compiler prompts you not to format the conversion, so I summarize several workarounds.
1. Convert Macros by t2w
char* szstr = "Balabala";
CString str = CString (SZSTR);
Uses_conversion;
LPCWSTR Wszclassname = new Wchar[str. GetLength () +1];
wcscpy ((LPTSTR) wszclassname,t2w ((LPTSTR) str. GetBuffer (NULL)));
Str. ReleaseBuffer ();
2, through the A2CW conversion
char* szstr = "Balabala";
CString str = CString (SZSTR);
Uses_conversion;
LPCWSTR Wszclassname = A2CW (W2A (str));
Str. ReleaseBuffer ();
3, through the swprintf () conversion
Char a[] = "c://";
Strcat (A, "balabala.wav");
WCHAR wsz[64];
swprintf (Wsz, L "%s", a);
LPCWSTR M_szfilename = Wsz;
4, LPCWSTR is actually a const WCHAR * type, can be converted by MultiByteToWideChar function
char* szstr = "Balabala";
WCHAR wszclassname[256];
memset (wszclassname,0,sizeof (wszclassname));
MultiByteToWideChar (Cp_acp,0,szstr,strlen (SZSTR) +1,wszclassname,
sizeof (Wszclassname)/sizeof (wszclassname[0]);
Hope to be helpful to everyone.