char tempFilename[256];
wchar_t filename[512];
fprintf(stdout, "Please enter file name/path: \n");
getchar();
fgets(tempFilename, 255, stdin);
MultiByteToWideChar(CP_ACP, 0, tempFilename, -1, filename, strlen(tempFilename)*2);
if((hReadFile = CreateFile(filename, GENERIC_READ , 0, 0, OPEN_EXISTING, 0, 0)) == INVALID_HANDLE_VALUE)
{
fprintf(stdout, "File could not be opened, make sure name is under 256 chars. Error Code - %d.\n", GetLastError());
return (0);
}
我检查了 MultiByteToWideChar() 是否成功。
事实上,我也尝试过像 C:\users\user_name\desktop\test.txt 这样的路径,而不是 C:\users\user_name\desktop\test.txt
我使用以下将 \ 转换为 \\
while(temp < len )
{
filename1[cntr1] = tempFilename[temp];
cntr1 += 1;
if(tempFilename[temp] == '\\')
{
filename1[cntr1] = '\\';
cntr1 += 1;
}
temp += 1;
}
这一直有效到 \ 到 \\。我哪里错了..?