Это довольно простой C-код для чтения текста файла, я делал это в другой раз, но не знаю, почему теперь функция ReadFile продолжает возвращать FALSE, означая, что она не работает..txt существует и функция CreateFile завершается успешно (или по крайней мере не возвращает INVALID_HANDLE_VALUE
#include <stdio.h>
#include <windows.h>
int main(int argc, char *argv[])
{
char ReadBuffer[256] = {0};
HANDLE hFile1;
int n = 0;
DWORD bytesread = 5;
printf("Press enter to read the file 'input.txt' ... ");
getch();
if ( (hFile1 = CreateFile(TEXT("input.txt"), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL) == INVALID_HANDLE_VALUE))
{
printf("INVALID_HANDLE_VALUE");
return -1;
}
if ( ReadFile(hFile1, ReadBuffer, bytesread, &bytesread, NULL) == FALSE )
{
printf("ReadFile ERROR");
CloseHandle(hFile1);
return -2;
}
printf("\n\nRead bytes: %d \n\n", bytesread);
CloseHandle(hFile1);
return 0;
}