如何使用 SetFilePointerEx 转到物理磁盘的末尾?
仅在设置位置时,我已经能够很好地使用 SetFilePointerEx
。
SetFilePointerEx(PD, 512, @PositionVar, FILE_BEGIN);
SetFilePointerEx(PD, 0, @PositionVar, FILE_CURRENT);
两者都有效;我可以设置位置,甚至可以检查我当前的位置。但是,当我根据文档设置 FILE_END 时,无论第二个参数是什么以及是否为第三个参数提供指针,它都会失败,即使在许多其他操作都可以的有效句柄上也是如此使用无误。
例如:
SetFailed := SetFilePointerEx(PD, 0, @PositionVar, FILE_END);
SetFailed := SetFilePointerEx(PD, 0, nil, FILE_END);
无论我输入什么,它都会失败。我正在使用物理磁盘的句柄,它肯定已经结束了。 SetFilePointer
工作得很好,但它只是比我想要的要麻烦一些。
这不是世界末日,而是正在发生的事情。
I have been able to use SetFilePointerEx
just fine, when setting the position only.
SetFilePointerEx(PD, 512, @PositionVar, FILE_BEGIN);
SetFilePointerEx(PD, 0, @PositionVar, FILE_CURRENT);
Both work; I can set positions and even check my current one. But when I set FILE_END
as per the documentation no matter what the second parameter is and whether or not I provide a pointer for the third parameter, it fails, even on a valid handle that many other operations are able to use without fail.
For example:
SetFailed := SetFilePointerEx(PD, 0, @PositionVar, FILE_END);
SetFailed := SetFilePointerEx(PD, 0, nil, FILE_END);
Whatever I put, it fails. I am working with a handle to a physical disk and it most definitely has an end. SetFilePointer
works just fine, but it's just a little more trouble than I would like.
It's not the end of the world, but whats happening.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如您所发现的,您不能这样做。你必须从头开始或从当前开始寻找。使用 DeviceIoControl 找出设备的大小。
You can't do this as you have found out. You have to seek from the beginning or current. Use DeviceIoControl to find out the size of the device.