Quantcast
Channel: The Old New Thing
Viewing all articles
Browse latest Browse all 24428

re: Don't forget, the fourth parameter to ReadFile and WriteFile is sometimes mandatory

$
0
0

@WndSks: 'just need to RTFM' - the trouble is that busy developers don't read the manual, or don't read it thoroughly enough, particularly for functions they 'know' how to use. The trouble with ReadFile is that it looks deceptively simple.

In theory, any ReadFile operation could return fewer bytes than were requested: therefore Windows has to be able to tell you how much of your buffer is valid. In the case of overlapped operations, this is stored in the OVERLAPPED structure; for non-overlapped it's the parameter you passed. In practice all synchronous buffered ReadFile operations that target a block device (i.e. a disk) will return the amount of data you asked for.

I wouldn't say that ReadFile and WriteFile have special checks for console handles. They have checks for the type of device they're talking to - remember that ReadFile can read from serial ports, consoles, raw devices, etc. *nix goes further: *everything* is modelled as a file (but again the file handle can reference a file that's part of a file system, a block device, a character device, etc).


Viewing all articles
Browse latest Browse all 24428

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>