gpt4 book ai didi

windows - SEEK_FAILURE 如果文件超过 4.1 GB,SetFilePointer 失败怎么办

转载 作者:行者123 更新时间:2023-12-05 03:17:40 24 4
gpt4 key购买 nike

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 时它会失败。

我该怎么做才能解决这个问题?

我读过 here,如果文件超过 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

谢谢!

最佳答案

简单的解决方案;改为调用 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

关于windows - SEEK_FAILURE 如果文件超过 4.1 GB,SetFilePointer 失败怎么办,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74026393/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com