[英]ReadFile() returning 1 with “lpNumberOfBytesRead” set to 0
I am using the VC++ function 我正在使用VC ++函数
ReadFile(FileHandle,charBuf,noOfBytesToRead,&noOfBytesRead,NULL);
inside a for loop; 在for循环中; in each iteration of the foor loop the FileHandle moves forward in the file ie in each iteration we are reading a particular unit of the file and copying that unit (bunch of data in file) of data in file to char *
array. 在foor循环的每次迭代中,FileHandle在文件中向前移动,即,在每次迭代中,我们正在读取文件的特定单元,并将该单元(文件中的数据束)复制文件中的数据到char *
array。
This amount of data to be read (from the file to char *
array) in each iteration is determined by "noOfBytesToRead". 每次迭代中要读取的数据量(从文件到char *
数组)由“ noOfBytesToRead”确定。
For some no: of iterations the ReadFile() is working fine but I observe that for some "n"th iteration (while reading nTH bunch of data) the 4th argument ( noOfBytesRead ) in the above call is set to 0 even though ReadFile() returns 1. 对于某些迭代:ReadFile()工作正常,但我观察到对于某些“第n次”迭代(在读取第n串数据时),即使ReadFile(),上述调用中的第4个参数( noOfBytesRead )也设置为0。 )传回1。
Return value of ReadFile() is 1 indicating success & the 4th parameter "noOfBytesRead" is set to 0, instead of no: of bytes Read. ReadFile()的返回值为1,表示成功,第4个参数“ noOfBytesRead”设置为0,而不是读取字节数:no。 This is contradictory! 这是矛盾的! Why is this so? 为什么会这样呢?
Can anyone kindly help me in this. 任何人都可以在这方面帮助我。 ReadFile() being an Win API I can't even step into code to debug further. ReadFile()是Win API,我什至无法进入代码进行进一步调试。
From the MSDN manual page : 从MSDN手册页 :
When a synchronous read operation reaches the end of a file, ReadFile returns TRUE and sets *lpNumberOfBytesRead to zero. 当同步读取操作到达文件末尾时,ReadFile返回TRUE,并将* lpNumberOfBytesRead设置为零。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.