Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

WriteFile gives error 112 (ERROR_DISK_FULL)

I've the following code which always results in Err.LastDllError reporting
error 112. If I omit SetFilePointer(hFile, -9&, 0&, FILE_CURRENT) or replace
-9 with a positive value, then WriteFile succeeds. I can't believe that it
is impossible to set the file pointer back to an earlier position using FILE_CURRENT.
Certainly I could use FILE_BEGIN again but that's kinda dumb if I'm far into
the file.

Mike

Dim hFile As Long
Dim lBytes As Long
Dim r As Long
Dim sData As String

hFile = CreateFile("d:\temp\filename.txt", GENERIC_READ Or GENERIC_WRITE,
_
0&, ByVal 0&, OPEN_EXISTING, 0&, 0&)

If hFile Then
Call SetFilePointer(hFile, 16, 0&, FILE_BEGIN)
If r <> INVALID_SET_FILE_POINTER Then
sData = Space(9)
Call ReadFile(hFile, sData, 9, lBytes, ByVal 0&)
Call SetFilePointer(hFile, -9&, 0&, FILE_CURRENT)
sData = UCase(sData)
r = WriteFile(hFile, sData, Len(sData), lBytes, ByVal 0&)
Debug.Print Err.LastDllError
End If
Call CloseHandle(hFile)
End If
[1102 byte] By [Mike Paschen] at [2007-11-10 0:20:50]