CreateFileA





VB.Net


Imports System.Runtime.InteropServices

Module CreateFileA
    Private Const GENERIC_WRITE As Int32 = &H40000000
    Private Const CREATE_NEW As Int32 = 1

    <DllImport("kernel32.dll", CharSet:=CharSet.Ansi)>
    Private Function CreateFileA(lpFileName As String, dwDesiredAccess As Integer, dwShareMode As Integer, lpSecurityAttributes As IntPtr, dwCreationDisposition As Integer, dwFlagsAndAttributes As Integer, hTemplateFile As IntPtr) As IntPtr
    End Function

    Sub CreateFileA_Main()
        Dim filename As String = "C:\kernel32\123.txt"
        Dim hFile As IntPtr = CreateFileA(filename, GENERIC_WRITE, 0, IntPtr.Zero, CREATE_NEW, 0, IntPtr.Zero)

        If hFile <> IntPtr.Zero Then
            ' File was created successfully
        Else
            ' Error handling
            Stop
        End If
    End Sub
End Module