locked
ReadFile() (C/C++) RRS feed

  • Question

  • Currently im programing a code that is supposed to read the bytes in a specified handle. In this case it's a filehandle from createfile() that i've obbtained through calling the devicepath in this function. The function is returning a open handle and i have it printing to a console to make sure i get a updated handle. Now the problems appear when trying to read the bytes in readfile(), the program is compailing just fine but i dont get the function to return true. The error code from GetLastError() is 1 and for readfile 1 points to the error: ERROR_INVALID_FUNCTION 

    This is how i've built the code:

    h = CreateFile(path.c_str(), GENERIC_READ | GENERIC_WRITE | STANDARD_RIGHTS_READ | STANDARD_RIGHTS_WRITE, FILE_READ_DATA | FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ALL_ACCESS, NULL);

        if (ReadFile(h, ReadBuffer, 3, &dwBytestransfer, NULL))
        {
            std::cout << "workning" << std::endl;
        }

    For now the (h) is standing for the handle to a device it the \??\ directory but i've also tried with a normal textfile andthe function is returning true and writing that it works on screen.

    How come i can't read device bytes for any sort of device if i know the funtions work. Is there an other way to read the bytes that the device is outputing with this handle and what would that be.

    Best regards from someone on the internet :) p.s i close the handle in the rest of the code xD

    Saturday, December 26, 2020 3:56 AM

All replies