CreateFile

The CreateFile function initiates a file access operation. It opens a file for reading, writing, appending, or random access. It also allows the user to set access rights, the file sharing mode, and other file attributes.

BOOL CreateFile( LPCTSTR lpFileName, // Pointer to the name of the file to open. DWORD dwOpenMode, // Specifies the type of access. DWORD dwAccessRights, // Specifies the access rights. LPSECURITY_ATTRIBUTES lpSecurityAttributes, // Pointer to a SECURITY_ATTRIBUTES structure. DWORD dwShareMode, // Specifies the file sharing mode. DWORD dwFileAttributeFlags, // Specifies file attribute flags. HANDLE hTemplateFile // Handle to a template file. );
Parameters:
lpFileName: Pointer to the name of the file to open.
dwOpenMode: Specifies the type of access (e.g., read, write).
dwAccessRights: Specifies the access rights (e.g., read, write).
lpSecurityAttributes: Pointer to a SECURITY_ATTRIBUTES structure. If NULL, no security attributes are used.
dwShareMode: Specifies the file sharing mode.
dwFileAttributeFlags: Specifies file attribute flags.
hTemplateFile: Handle to a template file. Not used in this function.
Return Value:
If the function succeeds, it returns a handle to the file. If it fails, it returns 0.
Error Codes:
See Error Codes for a list of possible error codes.

Access Modes: