CreateFileW

HANDLE CreateFileW(
  LPCWSTR lpFileName,
  DWORD dwDesiredAccess,
  DWORD dwShareMode,
  LPSECURITY_ATTRIBUTES lpSecurityAttributes,
  DWORD dwCreationDisposition,
  DWORD dwFlagsAndAttributes,
  HANDLE hTemplateFile
);

Description

The CreateFileW function (CreateFile is a macro for this function) creates or opens a file or I/O device (such as a serial port, communications resource, disk drive, or console buffer).

Parameters

Parameter Description
lpFileName The name of the file or device to be created or opened.
dwDesiredAccess The access to the file or device. This can be any combination of generic access rights (GENERIC_READ, GENERIC_WRITE, GENERIC_EXECUTE, GENERIC_ALL).
dwShareMode Specifies how the file or device should be shared. Can be 0, FILE_SHARE_READ, FILE_SHARE_WRITE, or FILE_SHARE_DELETE.
lpSecurityAttributes A pointer to a SECURITY_ATTRIBUTES structure that contains the security descriptor for the file or device.
dwCreationDisposition Specifies how to create or open the file. Possible values include CREATE_NEW, CREATE_ALWAYS, OPEN_EXISTING, OPEN_ALWAYS, and TRUNCATE_EXISTING.
dwFlagsAndAttributes The file attributes and extended attributes for the file or device.
hTemplateFile A handle to a template file with the attributes and extended attributes to be set for the file being created.

Return Value

If the function succeeds, the return value is an open handle to the specified file, device, named pipe, or mail slot. If the function fails, the return value is INVALID_HANDLE_VALUE. To get extended error information, call GetLastError.

Remarks

  • Use CreateFile to get a handle to the standard input, standard output, or standard error handle of a process.
  • The dwShareMode parameter determines whether another thread can access the file or device at the same time.
  • The dwCreationDisposition parameter controls how the file is opened or created.

Requirements

Minimum supported client: Windows 2000 Professional

Minimum supported server: Windows 2000 Server

Header: windows.h

Library: Kernel32.lib

DLL: Kernel32.dll

Note: For a complete list of Kernel32.dll functions, see Kernel Functions.