gpt4 book ai didi

c++ - ReadFile() 返回 1, "lpNumberOfBytesRead"设置为 0

转载 作者:搜寻专家 更新时间:2023-10-31 00:18:59 25 4
gpt4 key购买 nike

我正在使用VC++函数

ReadFile(FileHandle,charBuf,noOfBytesToRead,&noOfBytesRead,NULL);

在for循环内;在 foor 循环的每次迭代中,FileHandle 在文件中向前移动,即在每次迭代中,我们正在读取文件的特定单元并将文件中的数据单元(文件中的数据束)复制到 char *数组。

每次迭代中要读取的数据量(从文件到 char * 数组)由“noOfBytesToRead”决定。

对于某些 no: of 迭代,ReadFile() 工作正常,但我观察到对于某些“第 n”次迭代(在读取第 n 组数据时),第 4 个参数 (noOfBytesRead) 在即使 ReadFile() 返回 1,上述调用也设置为 0。

ReadFile() 的返回值为 1,表示成功,第 4 个参数“noOfBytesRead”设置为 0,而不是 no: of bytes Read。这是矛盾的!为什么会这样?

任何人都可以在这方面帮助我。 ReadFile() 是一个 Win API,我什至无法进入代码进行进一步调试。

最佳答案

来自 MSDN :

If the return value is nonzero and the number of bytes read is zero, the file pointer was beyond the current end of the file at the time of the read operation.

关于c++ - ReadFile() 返回 1, "lpNumberOfBytesRead"设置为 0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9173272/

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