This documentation is archived and is not being maintained.

IWriteStream Interface 

This interface provides methods for writing to and flushing a stream buffer.


__interface IWriteStream

This interface is implemented by CHttpResponse. The CWriteStreamHelper class provides type conversion methods that make this interface easier to use.

// This class implements the IWriteStream
// interface on top of a Windows file.
class CWriteStreamOnFile :
    public IWriteStream
{
public:
    
    HRESULT Initialize(LPCSTR szFileName)
    {
        return m_file.Create(szFileName, GENERIC_WRITE,
                             FILE_SHARE_READ, CREATE_ALWAYS);
    }

    HRESULT WriteStream(LPCSTR szOut, int nLen, LPDWORD pdwWritten)
    {
        if (nLen < 0)
        {
            nLen = (int) strlen(szOut);
        }

        DWORD dwWritten = 0;
        HRESULT hr = m_file.Write(szOut, nLen, &dwWritten);
        if (pdwWritten)
        {
            *pdwWritten = dwWritten;
        }

        return hr;
    }

    HRESULT FlushStream()
    {
        if (FlushFileBuffers(m_file))
        {
            return S_OK;
        }
        return AtlHresultFromLastError();
    }

private:
    CAtlFile m_file;
};

Header: atlsiface.h

Show: