Depending on your project configuration, _tprintf()
maps to either printf()
when TCHAR
maps to char
, or maps to wprintf()
for wchar_t
. Clearly your project is set to map TCHAR
to char
, which is why you are getting an error about passing a wchar_t*
to printf()
.
But, the code you showed is not using TCHAR
, so you should not be using _tprintf()
at all. m_szFilename
is explicitly a wchar_t[]
, so just use wprintf()
directly instead:
wprintf(m_szFilename);
Also, consider using wscanf()
to read the input as a wchar_t[]
to begin with and not use an intermediate char[]
:
WCHAR szExePath[MAX_PATH]; //
//L"C:\\Program Files (x86)\\Application Verifier\\vrfauto.dll"
printf("Please input the execution file path:\n");
wscanf(L"%259s", szExePath);
setlocale(LC_ALL, "chs");
wprintf(szExePath);
Note, however, that whether you use scanf()
or wscanf()
, reading stops on whitespace, so if the user enters a path like "C:\Program Files (x86)\Application Verifier\vrfauto.dll"
, your buffer will receive only "C:\Program
. To account for that, you would need to use gets()
/_getws()
(or the safer gets_s()
/_getws_s()
) or fgets()
/fgetws()
instead.