Expand Minimize

CreateXmlWriter

Creates a new IXmlWriter.


HRESULT CreateXmlWriter ([in] REFIID riid, [out] void ** ppvObject, [in] IMalloc * pMalloc);

riid

The reference ID.

ppvObject

An out argument that returns the writer.

pMalloc

An IMalloc implementation specified by the user. This parameter can be NULL.

Returns S_OK if no error is generated.

This constructor is used to create the writer. If no IMalloc is specified, the default implementation of IMalloc is used.

The following code shows the declaration of an IXmlWriter object; the declaration and creation of an IStream object; and the call to CreateXmlWriter:

// This code is excerpted from XmlLiteNamespaceWriter1.cpp.
int _tmain(int argc, _TCHAR* argv[])
{
    HRESULT hr;
    CComPtr<IStream> pOutFileStream;
    CComPtr<IXmlWriter> pWriter;

    if (argc != 2)
    {
        printf("Usage: XmlLiteNamespaceWriter1.exe name-of-output-file\n");
        return 0;
    }

    //Open writeable output stream
    if (FAILED(hr = FileStream::OpenFile(argv[1], &pOutFileStream, TRUE)))
    {
        wprintf(L"Error creating file writer, error is %08.8lx", hr);
        return -1;
    }

    if (FAILED(hr = CreateXmlWriter(__uuidof(IXmlWriter),(void**) &pWriter, NULL)))
    {
        wprintf(L"Error creating xml writer, error is %08.8lx", hr);
        return -1;
    }

    if (FAILED(hr = pWriter->SetOutput(pOutFileStream)))
    {
        wprintf(L"Error setting output for writer, error is %08.8lx", hr);
        return -1;
    }

Header: XmlLite.h

Library: XmlLite.lib

Show:
© 2014 Microsoft