title: MSXML2::IXMLDOMDocument2Ptr->GetXML() messing up my string!
body: <p>All,</p>
  
  <p>this is my code</p>
  
  <pre><code>//declare string pointer
  BSTR markup;
  
  //initialize markup to some well formed XML &lt;-
  
  //declare and initialize XML Document
  MSXML2::IXMLDOMDocument2Ptr pXMLDoc;
  HRESULT hr;
  hr = pXMLDoc.CreateInstance(__uuidof(MSXML2::DOMDocument40));
  pXMLDoc-&gt;async = VARIANT_FALSE;
  pXMLDoc-&gt;validateOnParse = VARIANT_TRUE;
  pXMLDoc-&gt;preserveWhiteSpace = VARIANT_TRUE;    
  
  //load markup into XML document
  vtBoolResult = pXMLDoc-&gt;loadXML(markup);
  
  //do some changes to the XML file&lt;-
  
  //get back string from XML doc
  markup = pXMLDoc-&gt;Getxml(); //&lt;-- this retrieves RUBBISH
  </code></pre>
  
  <p>At this point my string is mangled (just a few chinese characters at the start then rubbish) . Looks like an encoding issue.</p>
  
  <p>I also tried the following:</p>
  
  <pre><code>_bstr_t superMarkup = _bstr_t(markup);
  
  //did my stuff
  
  superMarkup = pXMLDoc-&gt;Getxml();
  
  markup = superMarkup; 
  </code></pre>
  
  <p>but still I am getting the same result.</p>
  
  <p>Even if I call GetXML() without changing anything in the xml document I still get rubbish.</p>
  
  <p>At this point if I try to assign the mangled pointer to another pointer it will trow an error:</p>
  
  <blockquote>
    <p>Attempted to restore write protected
    memory. this is often an indication
    that other memory is corrupted. </p>
  </blockquote>
  
  <p>Any suggestion?</p>
  
  <p>EDIT1:</p>
  
  <p><strong>I found out this is happening in relation to the size of the XML string. 
  If it happens on a given XML string and I reduce the size (keeping the same schema) it will work fine. Looks like MSXML2::DOMDocument40 has a limitation on size?
  In detail it happens if I have more than 16407 characters. I have one more GetXML will retrieve RUBBISH - if it's &lt;= 16407 everything works fine.</strong></p>
  
  <p>EDIT2:</p>
  
  <p><strong>Roddy was right - I was missing that <code>_bstr_t</code> is a class ...</strong></p>
  
  <p>Rings any bell?</p>
  
  <p>Cheers</p>