Ceci est une ancienne révision du document !


CreateFile

Déclaration

C:\lazarus2.0.2\fpc\3.0.4\source\rtl\win\wininc\ascdef.inc
function CreateFile(lpFileName:LPCSTR; dwDesiredAccess:DWORD; dwShareMode:DWORD; lpSecurityAttributes:LPSECURITY_ATTRIBUTES; dwCreationDisposition:DWORD;dwFlagsAndAttributes:DWORD; hTemplateFile:HANDLE):HANDLE; external 'kernel32' name 'CreateFileA';

Exemple d'utilisation

   Result := CreateFile(
                PChar(AFile),
                GENERIC_READ or GENERIC_WRITE,
                FILE_SHARE_READ or FILE_SHARE_WRITE,
                nil,
                OPEN_EXISTING,
                0,
                0);

Paramétres

lpFileName

pointeur vers le nom du fichier PChar(AFilename)

dwDesiredAccess
  • 0 : l'application peut interroger certaines métadonnées telles que les attributs de fichiers, de répertoires ou de périphériques sans accéder à ces fichiers ou périphériques.
  • GENERIC_READ ($8000 0000) : Accés en écriture
  • GENERIC_WRITE ($4000 0000) : Accés en Lecture
  • GENERIC_READ or GENERIC_WRITE ($C000 0000): Accés en écriture et lecture
  • FILE_ADD_FILE (2) : Pour un répertoire, le froits de créer un fichier dans ce répertoire.
  • FILE_ADD_SUBDIRECTORY (4) : For a directory, the right to create a subdirectory.
  • FILE_ALL_ACCESS : All possible access rights for a file.
  • FILE_APPEND_DATA (4) :
    • Pour un fichier : the right to append data to the file. (For local files, write operations will not overwrite existing data if this flag is specified without FILE_WRITE_DATA.)
    • Pour un répertoire: the right to create a subdirectory (FILE_ADD_SUBDIRECTORY).
  • FILE_CREATE_PIPE_INSTANCE (4) : For a named pipe, the right to create a pipe.
  • FILE_DELETE_CHILD ($40) : For a directory, the right to delete a directory and all the files it contains, including read-only files.
  • FILE_EXECUTE ($20) : For a native code file, the right to execute the file. This access right given to scripts may cause the script to be executable, depending on the script interpreter.
  • FILE_LIST_DIRECTORY (1) : For a directory, the right to list the contents of the directory.
  • FILE_READ_ATTRIBUTES (128/$80) :The right to read file attributes.
  • FILE_READ_DATA (1) : For a file object, the right to read the corresponding file data. For a directory object, the right to read the corresponding directory data.
  • FILE_READ_EA (8) : The right to read extended file attributes.
  • FILE_TRAVERSE (32/$20) : For a directory, the right to traverse the directory. By default, users are assigned the BYPASS_TRAVERSE_CHECKING privilege, which ignores the FILE_TRAVERSE access right. See the remarks in File Security and Access Rights for more information.
  • FILE_WRITE_ATTRIBUTES (256/$100) : The right to write file attributes.
  • FILE_WRITE_DATA (2) : For a file object, the right to write data to the file. For a directory object, the right to create a file in the directory (FILE_ADD_FILE).
  • FILE_WRITE_EA (16/$10) : The right to write extended file attributes.
  • STANDARD_RIGHTS_READ : Includes READ_CONTROL, which is the right to read the information in the file or directory object's security descriptor. This does not include the information in the SACL.
  • STANDARD_RIGHTS_WRITE : Same as STANDARD_RIGHTS_READ.

Vous ne pouvez pas demander un mode d'accès qui entre en conflit avec le mode de partage spécifié par le paramètre dwShareMode dans une requête ouverte qui a déjà un identifiant ouvert.

Apparement pour lire des données SMART sur un disque, il doit etre ouvert en GENERIC_READ or GENERIC_WRITE
dwShareMode
  • 0 ($0) : Empêche les autres processus d'ouvrir un fichier ou un périphérique s'ils demandent un accès en suppression, en lecture ou en écriture.
  • FILE_SHARE_DELETE ($4) : Permet aux opérations d'ouverture ultérieures sur un fichier ou un périphérique de demander un accès de suppression.
    Sinon, les autres processus ne peuvent pas ouvrir le fichier ou le périphérique s'ils demandent un accès par suppression.
    Si cet indicateur n'est pas spécifié, mais que le fichier ou le périphérique a été ouvert pour un accès par suppression, la fonction échoue.
    Remarque L'accès par suppression autorise les opérations de suppression et de renommage.
  • FILE_SHARE_READ ($1) : Permet aux opérations d'ouverture ultérieures sur un fichier ou un périphérique de demander un accès en lecture.
    Sinon, les autres processus ne peuvent pas ouvrir le fichier ou le périphérique s'ils demandent un accès en lecture.
    Si cet indicateur n'est pas spécifié, mais que le fichier ou le périphérique a été ouvert en lecture, la fonction échoue.
  • FILE_SHARE_WRITE ($2) : Enables subsequent open operations on a file or device to request write access.
    Otherwise, other processes cannot open the file or device if they request write access.
    If this flag is not specified, but the file or device has been opened for write access or has a file mapping with write access, the function fails.
lpSecurityAttributes
dwCreationDisposition
dwFlagsAndAttributes
hTemplateFile
Retourne : Handle
Vous pourriez laisser un commentaire si vous étiez connecté.