Hello,

I'm trying to overwrite a number of bytes in a file. Using the standard C libraries it would be a simple case of:-
Code:
FILE *fp;
unsigned char szData[] = "Hello";

fp = fopen("file", "w");
fseek(fp, 69, SEEK_SET);
fwrite(szData, strlen(szData), 1, fp);
fclose(fp);
But using the Win32 API does not seem to be as simple. Nice one M$.

The best I can come up with is:-
Code:
HANDLE hFile;
unsigned char szData[]= "Hello";
DWORD dwNumBytesWritten;

hFile = CreateFile("file", GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
SetFilePointer(hFile, 69, NULL, FILE_BEGIN);
WriteFile(hFile, szData, lstrlen(szData), &dwNumBytesWritten, NULL);
CloseHandle(hFile);
Sure, it writes the data, but appends it as opposed to overwriting it, increasing the size of the file. Is there a flag or sommat I'm missing?