I use CreateFile to initially create a file, with:
HANDLE hFile = CreateFile (TEXT(fileName.str().c_str()),
GENERIC_WRITE,
0,
NULL,
OPEN_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
NULL);
If I use CreateFile again to try and create the same file again, should it not be an error?
hFile = CreateFile (TEXT(fileName.str().c_str()),
GENERIC_WRITE,
0,
NULL,
CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
NULL);
I would have thought because I use CREATE_ALWAYS that it fails if the file is already created.
No, CREATE_ALWAYS flag makes
CreateFileto overwrite the file if it already exists. You should use CREATE_NEW to achieve what you want.