Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 79161
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T21:06:09+00:00 2026-05-10T21:06:09+00:00

All, this is my code //declare string pointer BSTR markup; //initialize markup to some

  • 0

All,

this is my code

//declare string pointer BSTR markup;  //initialize markup to some well formed XML <-  //declare and initialize XML Document MSXML2::IXMLDOMDocument2Ptr pXMLDoc; HRESULT hr; hr = pXMLDoc.CreateInstance(__uuidof(MSXML2::DOMDocument40)); pXMLDoc->async = VARIANT_FALSE; pXMLDoc->validateOnParse = VARIANT_TRUE; pXMLDoc->preserveWhiteSpace = VARIANT_TRUE;      //load markup into XML document vtBoolResult = pXMLDoc->loadXML(markup);  //do some changes to the XML file<-  //get back string from XML doc markup = pXMLDoc->Getxml(); //<-- this retrieves RUBBISH 

At this point my string is mangled (just a few chinese characters at the start then rubbish) . Looks like an encoding issue.

I also tried the following:

_bstr_t superMarkup = _bstr_t(markup);  //did my stuff  superMarkup = pXMLDoc->Getxml();  markup = superMarkup;  

but still I am getting the same result.

Even if I call GetXML() without changing anything in the xml document I still get rubbish.

At this point if I try to assign the mangled pointer to another pointer it will trow an error:

Attempted to restore write protected memory. this is often an indication that other memory is corrupted.

Any suggestion?

EDIT1:

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 <= 16407 everything works fine.

EDIT2:

Roddy was right – I was missing that _bstr_t is a class …

Rings any bell?

Cheers

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T21:06:09+00:00Added an answer on May 10, 2026 at 9:06 pm

    Try replacing

     BSTR Markup; 

    with

     bstr_t Markup; 

    BSTR is pretty much a dumb pointer, and I think that the return result of GetXML() is being converted to a temporary which is then destroyed by the time you get to see it. bstr_t wraps that with some smart-pointer goodness…

    Note: Your ‘SuperMarkup’ thing did NOT do what I suggested. Again, BSTR is just a pointer, and doesn’t ‘own’ what it points to. bstr_t, on the other hand does. I think your GetXML() function is returning a bstr_t, which is then being deleted as it goes out of scope, leaving your BSTR pointing to memory that is no longer valid.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 102k
  • Answers 102k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer SlikSVN (download) looks like the most appropriate option given what… May 11, 2026 at 8:15 pm
  • Editorial Team
    Editorial Team added an answer Yes, and easier than you think. When dismissModalViewControllerAnimated: is called,… May 11, 2026 at 8:15 pm
  • Editorial Team
    Editorial Team added an answer I would use @namespace for "strings" the methods would simply… May 11, 2026 at 8:15 pm

Related Questions

My question concerns c# and how to access Static members ... Well I don't
I'd like to implement the ViewModel part of WPF's MVVM pattern without referencing WPF
Recently our site has been deluged with the resurgence of the Asprox botnet SQL
I'm having trouble getting LINQ to translate something into the query I need. In

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.