Ahojte, na MSDN som nasiel kus kodu pomocou ktoreho mozem zapisovat text na koniec suboru. Vo funkcii CreateFile je priznak OPEN_EXISTING, cize mi nevie vytvorit textovy subor, ked som to zmenil na CREATE_ALWAYS tak sa vzdy text zapisuje na zaciatok suboru. Vedeli by ste mi poradit ako to prerobit tak aby mi tento kus kodu aj vytvoril textovy subor? Napada ma pred createfile vytvorit este jeden createfile kde bude CREATE_ALWAYS ale to mi nepride ako elegantne riesenie.
#include <windows.h>
#include <tchar.h>
#define FILE_WRITE_TO_END_OF_FILE 0xffffffff
int
_tmain(int argc, _TCHAR* argv[])
{
HANDLE hFile = ::CreateFile(L"Test.txt",
GENERIC_WRITE,
0,
0,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
0);
if ( hFile == INVALID_HANDLE_VALUE )
return ::GetLastError();
OVERLAPPED o;
::memset(&o, 0, sizeof(o));
o.Offset = FILE_WRITE_TO_END_OF_FILE;
o.OffsetHigh = -1;
DWORD dwBytesWritten;
if ( ! ::WriteFile(hFile, "This is a test\r\n", 16, &dwBytesWritten, &o) )
return ::GetLastError();
return 0;
}