_lclose





VB.Net


Imports System.Runtime.InteropServices

Module _LClose

    Private Const GENERIC_WRITE As Int32 = &H40000000
    Public Const GENERIC_READ As Int32 = &H80000000
    Public Const OPEN_EXISTING As Int32 = 3

    <DllImport("kernel32", CharSet:=CharSet.Ansi)>
    Private Function _lclose(ByVal hObject As IntPtr) As Boolean
    End Function

    <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 _lclose_Main()
        ' Open a file
        Dim hFile As IntPtr = CreateFileA("C:\kernel32\123.txt", GENERIC_READ Or GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0)

        ' Use the file
        ' ...

        ' Close the file
        _lclose(hFile)
    End Sub
End Module