I’m trying to output a formatted XML document from a DOM object into a string, as shown in the code below. The thing is, while the dom->get_xml() method does return a value, the MXXMLWriter->output does not, as you can see on the screenshot. All method calls return S_OK. What could be the issue here?
Here’s my code:
CComPtr<IMXWriter> w;
HRESULT hr;
hr = w.CoCreateInstance(__uuidof(MXXMLWriter), NULL, CLSCTX_INPROC_SERVER);
hr = w->put_indent(VARIANT_TRUE);
CComPtr<ISAXXMLReader> rd;
hr = rd.CoCreateInstance(__uuidof(SAXXMLReader60), NULL, CLSCTX_INPROC_SERVER);
CComPtr<ISAXContentHandler> hc;
hr = w.QueryInterface<ISAXContentHandler>(&hc);
CComPtr<ISAXErrorHandler> he;
hr = w.QueryInterface<ISAXErrorHandler>(&he);
CComPtr<ISAXDTDHandler> hd;
hr = w.QueryInterface<ISAXDTDHandler>(&hd);
hr = rd->putContentHandler(hc);
hr = rd->putErrorHandler(he);
hr = rd->putDTDHandler(hd);
hr = rd->putProperty(L"http://xml.org/sax/properties/lexical-handler", CComVariant(w));
hr = rd->putProperty(L"http://xml.org/sax/properties/declaration-handler", CComVariant(w));
BSTR body = ::SysAllocStringLen(NULL, 1024);
ZeroMemory(body, 1024 * sizeof(OLECHAR));
CComVariant out(body);
w->put_encoding(CComBSTR(L"utf-8"));
hr = w->put_output(out);
hr = rd->parse(CComVariant(dom));
dom->get_xml(&xmlStr);
return std::wstring(xmlStr);

The documentation states that
Output can be:
You apparently want the writer to fill the string. So it is suggested to use an empty string to instruct writer to fill its internal buffer and then you can obtain it via property getter.
You instead attempt to provide your own buffer to be filled, and this is the advertised behavior of the writer.