If SetFilePointer(hFile, 0&, ByVal 0&, FILE_END) _
= INVALID_SET_FILE_POINTER Then
此呼叫會HBF_SEEK_FAILURE在某個時間點引發錯誤 (45603)。
解碼后的 API 錯誤資訊為:
Seek Error Error 87 Wrong parameter
我相信當檔案大小超過 4.1 GB 時它會失敗。
我能做些什么來解決這個問題?
我在這里讀到,如果檔案超過 4 GB,則此錯誤是有效回應。所以我應該忽略它嗎?
根據一個建議,我現在使用的是 Ex 版本,但是我收到了 Wrong DLL Calling Convention 錯誤:
Public Sub SeekEnd()
RaiseErrorIfClosed
If SetFilePointerEx(hFile, 0&, ByVal 0&, FILE_END) _
= INVALID_SET_FILE_POINTER Then
RaiseError HBF_SEEK_FAILURE
End If
End Sub
謝謝!
uj5u.com熱心網友回復:
簡單的解決方案;SetFilePointerEx而是打電話。
如果你想繼續使用SetFilePointer大檔案,那么你應該將 lpDistanceToMoveHigh 引數設定為一個有效的指標(在這種特定情況下它可能指向一個值為 0 的值)。
當設定 lpDistanceToMoveHigh 時,您可以像這樣檢查回傳值:
If SetFilePointer(...) = INVALID_SET_FILE_POINTER _
AndAlso If Not Err.LastDLLError = 0
' Handle error
Else
' Success
End If
這是使用 SetFilePointerEx 的版本
Private Declare Function SetFilePointerEx Lib "kernel32" ( _
ByVal hFile As Long, _
ByVal liDistanceToMove As Currency, _
ByRef lpNewFilePointer As Currency, _
ByVal dwMoveMethod As Long) As Boolean
Public Function SeekEOF() As Currency
' NEW
' Seek to a base 0 EOF and return the pointer position
' The returned value is the new ABSOLUTE pointer positon.
Dim RetVal As Long
Dim tmpPosition As Currency
Dim returnedPosition As Currency
RaiseErrorIfClosed
tmpPosition = 0@
RetVal = SetFilePointerEx(hFile, (tmpPosition), returnedPosition, FILE_END) ' seek relative to the END of the file. thius returns a pointer to the final byte ?
If RetVal = 0 Then ' failed
RaiseError HBFH_SEEK_FAILURE
End If
fCurrentPointerPosition = (returnedPosition) * 10000@
If fCurrentPointerPosition <> Me.fileSize() Then 'gosh, what could have happened ? BASE 0 compared to BASE 1 position should=file size (ie 1 past the last byte!)
RaiseError HBFH_SEEK_FAILURE
End If
SeekEOF = fCurrentPointerPosition ' returns the BASE 0 absolute pointer positon which is 1 past the last byte
End Function
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/514436.html
