I'm trying to overwrite a number of bytes in a file. Using the standard C libraries it would be a simple case of:-
But using the Win32 API does not seem to be as simple. Nice one M$.
unsigned char szData = "Hello";
fp = fopen("file", "w");
fseek(fp, 69, SEEK_SET);
fwrite(szData, strlen(szData), 1, fp);
The best I can come up with is:-
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?
unsigned char szData= "Hello";
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);