_lopen





VB.Net


Imports System.Runtime.InteropServices

Module _LOpen

    Public Const GENERIC_WRITE As Int32 = &H40000000
    Public Const GENERIC_READ As Int32 = &H80000000

    <DllImport("kernel32", EntryPoint:="_lopen")>
    Private Function _lopen(ByVal lpPathName As String, ByVal dwDesiredAccess As Integer) As IntPtr
    End Function

    <DllImport("kernel32", SetLastError:=True)>
    Private Function CloseHandle(hObject As IntPtr) As Boolean
    End Function

    Public Sub fileOpen2()
        Dim filePath As String = "C:\kernel32\123.txt"
        Dim accessFlags As Integer = GENERIC_READ Or GENERIC_WRITE

        Dim hFile As IntPtr = _lopen(filePath, accessFlags)

        If hFile <> IntPtr.Zero Then
            ' File was created and opened successfully
            ' Use the file handle as needed...
            CloseHandle(hFile) ' Don't forget to close the file when you're done!
        Else
            ' Error opening the file
            Stop
        End If
    End Sub

End Module