• ReadFile
  • GetLastError.
  • Introduction




    Download 1,09 Mb.
    bet41/62
    Sana21.03.2017
    Hajmi1,09 Mb.
    #917
    1   ...   37   38   39   40   41   42   43   44   ...   62
    BOOL ReadFile(

    HANDLE hFile,

    LPVOID lpBuffer,

    DWORD nNumberOfBytesToRead,

    LPDWORD lpNumberOfBytesRead,

    LPOVERLAPPED lpOverlapped );

    Parameters

    hFile

    Handle to the file to be read. The file handle must have been created with GENERIC_READ access to the file. This parameter cannot be a socket handle.



    lpBuffer

    Pointer to the buffer that receives the data read from the file.



    nNumberOfBytesToRead

    Number of bytes to be read from the file.



    lpNumberOfBytesRead

    Pointer to the number of bytes read. ReadFile sets this value to zero before doing any work or error checking.



    lpOverlapped

    Unsupported; set to NULL.



    Return Values

    The ReadFile function returns when one of the following is true: the number of bytes requested has been read or an error occurs.

    Nonzero indicates success. If the return value is nonzero and the number of bytes read is zero, the file pointer was beyond the current end of the file at the time of the read operation. Zero indicates failure. To get extended error information, call GetLastError.

    //Write to a file

    The file can be read by the handler only if it is opened in GENERIC_WRITE mode using CreateFile. Thus the call to read file must come after the file is opened appropriately.

    WriteFile (exampleHandler,wbuff,cBytes,&writeBytes,NULL);


    Here the character array wbuff is written into the file specified by the exampleHandler where cBytes specifies number of bytes to be written and writeBytes will contain the number of bytes actually written into the file. writeBytes is passed by address so that it can be modified in WriteFile and the modifications will be visible in the calling function.

    API Reference to WriteFile:

    This function writes data to a file. WriteFile starts writing data to the file at the position indicated by the file pointer. After the write operation has been completed, the file pointer is adjusted by the number of bytes actually written.


    Download 1,09 Mb.
    1   ...   37   38   39   40   41   42   43   44   ...   62




    Download 1,09 Mb.