You are creating a file and leaving it open write only with a share mode of zero (meaning it can not be shared) and throwing away its handle and then trying to reopen the file for reading with the xml parser.
You probably want to CloseHandle() on the return value for ::CreateFile()
HANDLE hFile = ::CreateFile(pathName,GENERIC_WRITE,0,NULL,CREATE_NEW, FILE_ATTRIBUTE_NORMAL|FILE_FLAG_SEQUENTIAL_SCAN,NULL);
if (hFile == INVALID_HANDLE_VALUE) {
// Call GetLastError() to figure out why the file creation failed.
}
else
{
CloseHandle(hFile);
}