VBcoders Browse New Submit Contact Sign In

No account? Register free

Forgot password?

File I/O using API calls

DTA  (1 Submission)   Windows API Call/Explanation   VB 6.0   Unknown Difficulty   Mon 4th January 1999   Mon 8th February 2021

File I/O using API calls

API Declarations



'Reads input from the file
Declare Function ReadFile Lib "kernel32" _
(ByVal hFile As Long, lpBuffer As Any, _
ByVal nNumberOfBytesToRead As Long, lpNumberOfBytesRead As Long, _
ByVal lpOverlapped As Long) As Long

'Closes the file
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long

'Outputs to the file
Private Declare Function WriteFile Lib "kernel32" _
(ByVal hFile As Long, lpBuffer As Any, ByVal nNumberOfBytesToWrite As Long, _
lpNumberOfBytesWritten As Long, ByVal lpOverlapped As Long) As Long

'Opens the file (grabs a file handle)
Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" _
(ByVal lpFileName As String, ByVal dwDesiredAccess As Long, _
ByVal dwShareMode As Long, ByVal lpSecurityAttributes As Long, _
ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, _
ByVal hTemplateFile As Long) As Long

'Output the data on hold to the file
Declare Function FlushFileBuffers Lib "kernel32" _
(ByVal hFile As Long) As Long

'Find out how big the file is
Declare Function GetFileSize Lib "kernel32" _
(ByVal hFile As Long, lpFileSizeHigh As Long) As Long

Const GENERIC_WRITE = &H40000000
Const GENERIC_READ = &H80000000
Const FILE_ATTRIBUTE_NORMAL = &H80
Const CREATE_ALWAYS = 2
Const OPEN_ALWAYS = 4
Const INVALID_HANDLE_VALUE = -1

'This array type must be used to print and read to the file
Type FileString
Value As Integer
End Type

Private minFileCount As Integer 'Number of files open
Private mblFileInput() As Boolean 'If the file has been read in yet
Private mlgFileCursor() As Long 'The current position of the cursor in the file
Private mlgFileHandles() As Long 'List of file handles opened
Private mstFileData() As String 'Data inputted from a file


Rate File I/O using API calls (1(1 Vote))
File I/O using API calls.bas

File I/O using API calls Comments

No comments yet — be the first to post one!

Post a Comment

0/1000 characters