+ Reply to Thread
Results 1 to 2 of 2

Thread: Zapis na koniec suboru (Win API)

  1. #1

    Zapis na koniec suboru (Win API)

    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.

    Code:
    #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;
    }

  2. #2
    Ono to vyznie hlupo ale neskusal si nieco ako FILE* subor, a nasledne subor = fopen()? ono by to vytvorilo txt file automaticky bez ohladu na to, v akom OS sa nachadzas. Je vsak pravda ze to je velmy primitivne riesenie.
    Všetko o hrách a novinkách s herného sveta nájdete na http://the-guild.cz/.

+ Reply to Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts