Handmade Hero»Forums»Code
Jesse Coyle
37 posts
WriteFile seems to... not write to the file
Heyo, I've been using WriteFile to write to a file. And previously it worked fine, although I'm not sure what changed that would allow it to not write anymore... Some more info:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
void
saveFile(FileInfo *file, char *filename)
{
    HANDLE fileHandle = CreateFileA(filename, GENERIC_WRITE, 0, 0, CREATE_ALWAYS, 0, 0);
    if(fileHandle != INVALID_HANDLE_VALUE)
    {
        DWORD bytesWritten;
        int error = WriteFile(fileHandle, (void *)file->contents, (DWORD)file->filesize, &bytesWritten, 0);

        CloseHandle(fileHandle);
    }
}


So WriteFile doesn't return any errors, and it have a fileHandle, and GetLastError returns that the file already exists. bytesWritten is always exactly how many bytes I want to be written (the filesize).

The only thing I can think of that might have changed inbetween those times is that I add a null at the end of the file, but I don't include it when saving the file. Would a null be preventing the WriteFile from completing it's task?
Jesse Coyle
37 posts
WriteFile seems to... not write to the file
Gosh dangit... This always happens to me... I got it, I'm retarded.

How do I delete this forum post?
hugo schmitt
7 posts
from brazil! more used to write python/golang/lua/js and want to try something lower level / more complex for a change
WriteFile seems to... not write to the file
Now you have to tell us what you were doing wrong :)
498 posts
WriteFile seems to... not write to the file
Edited by ratchetfreak on
Exactly don't be a DenverCoder9
Timothy Wright
76 posts / 1 project
WriteFile seems to... not write to the file
I have this cartoon on my door at work.
Jesse Coyle
37 posts
WriteFile seems to... not write to the file
Edited by Jesse Coyle on Reason: realized it's a spoiler
I literally had it writing to a hardcoded filename, so even if I loaded foo.wat it was going to save to hardcoded bar.omg.

Not exactly a satisfying answer. :c