• CreateFile
  • GetLastError
  • Introduction




    Download 1,09 Mb.
    bet40/62
    Sana21.03.2017
    Hajmi1,09 Mb.
    #917
    1   ...   36   37   38   39   40   41   42   43   ...   62
    Value

    Description

    FILE_ATTRIBUTE_ARCHIVE

    The file should be archived. Applications use this attribute to mark files for backup or removal.

    FILE_ATTRIBUTE_HIDDEN

    The file is hidden. It is not to be included in an ordinary directory listing.

    FILE_ATTRIBUTE_NORMAL

    The file has no other attributes set. This attribute is valid only if used alone.

    FILE_ATTRIBUTE_READONLY

    The file is read only. Applications can read the file but cannot write to it or delete it.

    FILE_ATTRIBUTE_SYSTEM

    The file is part of or is used exclusively by the operating system.

    FILE_ATTRIBUTE_TEMPORARY

    Not supported.


    hTemplateFile

    Ignored; as a result, CreateFile does not copy the extended attributes to the new file.



    Return Values

    An open handle to the specified file indicates success. If the specified file exists before the function call and dwCreationDisposition is CREATE_ALWAYS or OPEN_ALWAYS, a call to GetLastError returns ERROR_ALREADY_EXISTS, even though the function has succeeded. If the file does not exist before the call, GetLastError returns zero. INVALID_HANDLE_VALUE indicates failure. To get extended error information, call GetLastError.

    //Read a file

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

    ReadFile(exampleHandler,rbuff,cBytes,&readBytes,NULL);
    Here the file is read into the character array rbuff where cBytes specifies number of bytes to be read and readBytes will contain the number of bytes actually read from the file. readBytes is passed by address so that it can be modified in ReadFile and the modifications will be visible in the calling function.

    API reference to ReadFile:

    This function reads data from a file, starting at the position indicated by the file pointer. After the read operation has been completed, the file pointer is adjusted by the number of bytes actually read.


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




    Download 1,09 Mb.