gpt4 book ai didi

c++ - 使用 ReadFile 时是否更新了重叠结构?

转载 作者:太空狗 更新时间:2023-10-29 23:01:48 26 4
gpt4 key购买 nike

我正在学习一些有关 win32 编程的知识。我阅读了引用手册(此处:https://msdn.microsoft.com/en-us/library/windows/desktop/aa365467%28v=vs.85%29.aspx)

If lpOverlapped is not NULL, the read operation starts at the offset that is specified in the OVERLAPPED structure and ReadFile does not return until the read operation is complete. The system updates the OVERLAPPED offset before ReadFile returns.

但是,如果我调用 ReadFile(hmyFile, &myrecord, sizeof(record_t), &n, &ov);,我会看到值 ov.offset 保持不变。为何如此?我在哪里误解了引用手册中的内容?

更多详情:
文件处理程序打开为我没有使用 FILE_FLAG_OVERLAPPED

最佳答案

如注释所示,这是文档中的一个错误。实际行为是更新文件指针,就像 lpOverlapped 为 NULL 且句柄同步时一样。旧版本的文档是正确的。以下内容摘自 2000 年 7 月版的 Platform SDK 文档:

The ReadFile function reads data from a file, starting at the position indicated by the file pointer. After the read operation has been completed, the file pointer is adjusted by the number of bytes actually read, unless the file handle is created with the overlapped attribute. [...]

If hFile is not opened with FILE_FLAG_OVERLAPPED and lpOverlapped is not NULL, the read operation starts at the offset specified in the OVERLAPPED structure. ReadFile does not return until the read operation has been completed.

关于c++ - 使用 ReadFile 时是否更新了重叠结构?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30278873/

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