ファイルから取得したパスへのファイル ハンドラーを開こうとしています。たとえば、c:\def\es1.txt などのフル パスを含む入力ファイルがあります。
「\」文字を2倍の「\」に置き換えたので、文字列形式に適合し、次を使用しています:
myfile = fopen("temp.txt", "r");
while (fgets(line, line_size, myfile) != NULL){
printf("==============================\n");
printf(line);
system("PAUSE\n");
mbstowcs(wtext, line, strlen(line) + 1);//Plus null
_tprintf(wtext);
LPWSTR ptr = wtext;
hFile = CreateFile(wtext, // name of the write
GENERIC_WRITE, // open for writing
0, // do not share
NULL, // default security
OPEN_EXISTING, // create new file only
FILE_ATTRIBUTE_NORMAL, // normal file
NULL); // no attr. template
if (hFile == INVALID_HANDLE_VALUE)
{
DisplayError(TEXT("CreateFile"));
_tprintf(TEXT("Terminal failure: Unable to open file \"%s\" for write.\n"), wtext);
return;
}
else {
printf("yes!!!!!!!\n");
}
コマンド _tprintf(wtext); 「c:\def\es1.txt」という文字列が表示されます。
ただし、CreateFile コマンドは失敗します。
FATAL ERROR: Unable to output error code.
ERROR: CreateFile failed with error code 123 as follows:
The filename, directory name, or volume label syntax is incorrect.
Terminal failure: Unable to open file "c:\\def\\es1.txt
" for write.
CreateFile の wtext 変数を次のように置き換えると、正常L"c:\\def\\es1.txt"
に動作しますが、何が問題なのですか?