// CStreamOnCString
// This is a helper class used by the CHtmlEditCtrlBase class to stream
// HTML into and out of the web browser control.
class CStreamOnCString : public IStream
{
public:
// Construction
CStreamOnCString()
{
m_current_index = 0;
}
STDMETHOD(Read)(void *pv, ULONG cb, ULONG *pcbRead)
{
if (pcbRead)
*pcbRead = 0;
if (m_strAnsi.GetLength() == 0)
m_strAnsi = m_strStream;
if (!pv)
return E_POINTER;
unsigned int length = m_strAnsi.GetLength();
char *pStream = m_strAnsi.GetBuffer();
if (!pStream)
return E_UNEXPECTED;
char *pStart = pStream + m_current_index;
char *pEnd = pStream + length;
if (pStart >= pEnd)
return S_FALSE; // no more data to read
int bytes_left = (int)(pEnd-pStart);
int bytes_to_copy = (int)min(bytes_left, (int)cb);
if (bytes_to_copy <= 0)
{
// reset members so this stream can be used again
m_current_index = 0;
m_strAnsi.Empty();
return S_FALSE;
}