WriteFile help (Win32).

This is a discussion on WriteFile help (Win32). within the Windows Programming forums, part of the Platform Specific Boards category; This is my first real use of the win32 api for file i/o and I can't seem to get it ...

  1. #1
    Sindolist
    Guest

    WriteFile help (Win32).

    This is my first real use of the win32 api for file i/o and I can't seem to get it to work.

    The goal is to save an xml file with some config settings when the program exits, but I can't seem to get the stupid file to write anything and I have a feeling I am handling the buffers or the string manipulation wrong.

    I'm trying to use the win32 api and not iostream, ect ..

    Here's the write file section:

    Code:
    HANDLE hConfig = NULL;
    DWORD dwWrittenBuffer = 0;
    TCHAR *szWriteBuffer = NULL;
    
    
    hConfig = CreateFile(
       _T("config.xml"), 
       GENERIC_WRITE, 
       FILE_SHARE_WRITE,
       NULL,
       CREATE_ALWAYS,
       0,
       0);
    
    if(hConfig != INVALID_HANDLE_VALUE)
    {
    
       lstrcat(szWriteBuffer, _T("<config>"));
       // do rest of stuff when this works
       lstrcat(szWriteBuffer, _T("</config>"));
       WriteFile(hConfig, szWriteBuffer, lstrlen(szWriteBuffer) + 1, &dwWrittenBuffer, 0);
       CloseHandle(hConfig);
    
    }
    Unfortunately my config file comes out empty, so I'm stumped how I'm supposed to handle this, I don't wanna just do a buttload of WriteFiles line for line, I'd rather write it all at once using lstrcat on a single buffer, like I said I'm probably doing the buffer all wrong so any help would be appreciated.

  2. #2
    Used Registerer jdinger's Avatar
    Join Date
    Feb 2002
    Posts
    1,065
    In the 2nd to last param you're passing 0. If you look up the values of the possible values, 0 isn't valid.

    Try using FILE_ATTRIBUTE_NORMAL there.

    Code:
    hConfig = CreateFile(
       _T("config.xml"), 
       GENERIC_WRITE, 
       FILE_SHARE_WRITE,
       NULL,
       CREATE_ALWAYS,
       0,
       0);

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Win32 API or Win32 SDK?
    By jverkoey in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 07-20-2005, 03:26 PM
  2. Win32 Thread Object Model Revisted
    By Codeplug in forum Windows Programming
    Replies: 5
    Last Post: 12-15-2004, 07:50 AM
  3. OLE Clipboard :: Win32 API vs. MFC
    By kuphryn in forum Windows Programming
    Replies: 3
    Last Post: 08-11-2002, 05:57 PM
  4. Thread Synchronization :: Win32 API vs. MFC
    By kuphryn in forum Windows Programming
    Replies: 2
    Last Post: 08-09-2002, 09:09 AM
  5. Win32 API Tutorials?
    By c++_n00b in forum C++ Programming
    Replies: 9
    Last Post: 05-09-2002, 03:51 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21