Why does WriteFile crash when writing to the standard output? Why does WriteFile crash when writing to the standard output? windows windows

Why does WriteFile crash when writing to the standard output?


The fourth parameter to WriteFile is not optional. You are passing NULL, which is not allowed.


4th parameter (which tells us how much bytes were actually written) is expecting pointer to DWORD value (a.k.a unsigned int) when you pass NULL to that parameter it attempts to write DWORD to null pointer which causes exception, not only it is mandatory to pass pointer to that argument but also you should always check its value after write because there is probability although slim that WriteFile will write less data than you provided.