I'm trying to use CreateFile
function, but it does not go as planned.
I did a simple test code :
#include <Windows.h> #include <iostream> #include <tchar.h> using namespace std; int main() { HANDLE hFile; hFile = CreateFile(_T("test.txt"), GENERIC_READ, NULL, NULL, OPEN_EXISTING, NULL, NULL); if (hFile == INVALID_HANDLE_VALUE) { cout << GetLastError() << endl; Sleep(2000); return EXIT_FAILURE; } return EXIT_SUCCESS; }
I generate the .exe
and place a file test.txt
in the same folder.
When I execute the .exe
I get getLastError() = 2
which means ERROR_FILE_NOT_FOUND
How is it even possible?