Kernel32CreateFileW(String, Int32, FileShare, IntPtr, FileMode, UInt32, 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.Unicode, SetLastError = true)]
public static SafeFileHandle CreateFileW(
string filepath,
int access,
FileShare share,
IntPtr securityAttributes,
FileMode creationDisposition,
uint flagsAndAttributes,
IntPtr templateFile
)
<DllImportAttribute("Kernel32.dll", CharSet := CharSet.Unicode, SetLastError := true>]
Public Shared Function CreateFileW (
filepath As String,
access As Integer,
share As FileShare,
securityAttributes As IntPtr,
creationDisposition As FileMode,
flagsAndAttributes As UInteger,
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 flagsAndAttributes As UInteger
Dim templateFile As IntPtr
Dim returnValue As SafeFileHandle
returnValue = Kernel32.CreateFileW(filepath,
access, share, securityAttributes,
creationDisposition, flagsAndAttributes,
templateFile)
public:
[DllImportAttribute(L"Kernel32.dll", CharSet = CharSet::Unicode, SetLastError = true)]
static SafeFileHandle^ CreateFileW(
String^ filepath,
int access,
FileShare share,
IntPtr securityAttributes,
FileMode creationDisposition,
unsigned int flagsAndAttributes,
IntPtr templateFile
)
[<DllImportAttribute("Kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)>]
static member CreateFileW :
filepath : string *
access : int *
share : FileShare *
securityAttributes : IntPtr *
creationDisposition : FileMode *
flagsAndAttributes : uint32 *
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.
- 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.
- flagsAndAttributes UInt32
-
The file or device attributes and 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.