We value your feedback.
Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!
Dim InpFile As String Dim OutFile As String Dim hFile As Long Dim fileStruct As OFSTRUCT Dim FSize As Long Dim BytesRead As Long Dim BytesWritten As Long Dim hMem As Long Dim lpMem As Long Dim r As Long Dim bts As Byte InpFile = "input.txt" OutFile = "OUTPUT.txt" 'Get the size of the file to be read FSize = FileLen(InpFile) If FSize > 0 Then 'Allocate a block of memory equal to the size of the input file. 'hMem = GlobalAlloc(GMEM_ZEROINIT, FSize) hMem = GlobalAlloc(GPTR, FSize) If hMem <> 0 Then lpMem = GlobalLock(hMem) 'Read the file into memory hFile = OpenFile(InpFile, fileStruct, OF_READ Or _ OF_SHARE_DENY_NONE) BytesRead = hread(hFile, ByVal lpMem, FSize) MsgBox Format(BytesRead) & " bytes read into memory" r = lclose(hFile) 'Write the file back to disk to verify the file was 'read correctly hFile = OpenFile(OutFile, fileStruct, OF_CREATE Or _ OF_WRITE Or OF_SHARE_DENY_NONE) BytesWritten = hwrite(hFile, ByVal lpMem, FSize) MsgBox Format(BytesWritten) & " bytes written to output file" r = lclose(hFile) 'Free resources r = GlobalUnlock(hMem) r = GlobalFree(hMem) Else MsgBox "Not enough memory to store file" End If Else MsgBox "Input file is zero bytes in length" End If End