Kernel32CreateFileA(String, Int32, FileShare, IntPtr, FileMode, CreateFileFlags, IntPtr) Method
Creates or opens a file or I/O device.
The most commonly used I/O devices are as follows:
file, file stream, directory, physical disk, volume, console buffer, tape drive,
communications resource, mailslot, and pipe.
The function returns a handle that can be used to access the file or device
for various types of I/O depending on the file or device and the flags and attributes specified.
Namespace: DevCase.Win32.NativeMethodsAssembly: DevCase.net48 (in DevCase.net48.dll) Version: 6.0.0.0 (6.0)
XMLNS for XAML: Not mapped to an xmlns.
[DllImportAttribute("Kernel32.dll", CharSet = CharSet.Ansi, BestFitMapping = false,
ThrowOnUnmappableChar = true, SetLastError = true)]
public static SafeFileHandle CreateFileA(
string filepath,
int access,
FileShare share,
IntPtr securityAttributes,
FileMode creationDisposition,
CreateFileFlags flags,
IntPtr templateFile
)
<DllImportAttribute("Kernel32.dll", CharSet := CharSet.Ansi, BestFitMapping := false,
ThrowOnUnmappableChar := true, SetLastError := true>]
Public Shared Function CreateFileA (
filepath As String,
access As Integer,
share As FileShare,
securityAttributes As IntPtr,
creationDisposition As FileMode,
flags As CreateFileFlags,
templateFile As IntPtr
) As SafeFileHandle
Dim filepath As String
Dim access As Integer
Dim share As FileShare
Dim securityAttributes As IntPtr
Dim creationDisposition As FileMode
Dim flags As CreateFileFlags
Dim templateFile As IntPtr
Dim returnValue As SafeFileHandle
returnValue = Kernel32.CreateFileA(filepath,
access, share, securityAttributes,
creationDisposition, flags, templateFile)
public:
[DllImportAttribute(L"Kernel32.dll", CharSet = CharSet::Ansi, BestFitMapping = false,
ThrowOnUnmappableChar = true, SetLastError = true)]
static SafeFileHandle^ CreateFileA(
String^ filepath,
int access,
FileShare share,
IntPtr securityAttributes,
FileMode creationDisposition,
CreateFileFlags flags,
IntPtr templateFile
)
[<DllImportAttribute("Kernel32.dll", CharSet = CharSet.Ansi, BestFitMapping = false,
ThrowOnUnmappableChar = true, SetLastError = true)>]
static member CreateFileA :
filepath : string *
access : int *
share : FileShare *
securityAttributes : IntPtr *
creationDisposition : FileMode *
flags : CreateFileFlags *
templateFile : IntPtr -> SafeFileHandle
No code example is currently available or this language may not be supported.
- filepath String
-
The name of the file or device to be created or opened.
In the ANSI version of this function (CreateFileA(String, FileAccessRights, FileShare, IntPtr, FileMode, CreateFileFlags, IntPtr)),
the name is limited to MAX_PATH characters.
To extend this limit to 32,767 wide characters,
call the Unicode version of the function (CreateFileW(String, FileAccessRights, FileShare, IntPtr, FileMode, CreateFileFlags, IntPtr))
and prepend "\\?\" to the path, for example: CreateFileW("\\?\C:\Very Long Path\File.txt")
- access Int32
-
The requested access to the file or device,
which can be summarized as read, write, both or neither zero.
- share FileShare
-
The requested sharing mode of the file or device,
which can be read, write, both, delete, all of these, or none (refer to the following table).
Access requests to attributes or extended attributes are not affected by this flag.
- securityAttributes IntPtr
-
A pointer to a SECURITY_ATTRIBUTES structure
that contains two separate but related data members:
an optional security descriptor, and a Boolean value that determines whether
the returned handle can be inherited by child processes.
- creationDisposition FileMode
-
An action to take on a file or device that exists or does not exist.
- flags CreateFileFlags
-
The file or device flags.
- templateFile IntPtr
-
A valid handle to a template file with the GENERIC_READ access right.
The template file supplies file attributes and extended attributes for the file that is being created.
SafeFileHandle
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 a
INVALID_HANDLE_VALUE value (
IntPtr(-1)).
To get extended error information, call
GetLastWin32Error.