Tuesday, October 13, 2009

How To Use the String Stream implementation of ISequentialStream

Someone the other day asked how do they use the ISequentialStream string class I implemented.

Here is the original post on the string stream implementation.

This is how you would use it.

HRESULT hr = S_OK;
LPWSTR pszXml = NULL;
ISequentialStream *pStream = NULL;
IXmlReader *pReader = NULL;

hr = GetXmlString(&pszXml);

if (S_OK == hr)
{
hr = CStringStream::Create(pszXml, &pStream);
}

if (S_OK == hr)
{
hr = CreateXmlReader(__uuidof(IXmlReader), (void**)&pReader, NULL);
}

if (S_OK == hr)
{
hr = pReader->SetInput(pStream);
}

//
// rest of your xml parsing here.
//

// cleanup
if (pReader)
{
pReader->Release();
}

if (pStream)
{
pStream->Release();
}

if (pszXml)
{
free(pszXml);
}

No comments:

Post a Comment