This is a C question and not a C++ question.

However without knowing the how WriteToFile is called, what you have done before that and so on it is hard to tell...do you check that a file is properly opened before calling WriteToFile (I see you do a check in the function but that is only done before writing to the file, you may attempt to seek using an invalid file handle)?