MSXML - CXX0030:Error:expression cannot be evaluated.

I got a error "CXX0030:Error:expression cannot be evaluated." when I am trying to add a node into a xml file using VC++ 2010. I choose MSXML6.dll in the #import statement.

Here is my code:

#include <iostream>
#import "msxml6.dll"
using namespace MSXML2;

int main()
{
MSXML2::IXMLDOMElementPtr m_pElement; //point to a node in xml file
MSXML2::IXMLDOMElementPtr m_pParElement; //the parent node of an element
MSXML2::IXMLDOMElementPtr m_pChildElement; //child node of an element
MSXML2::IXMLDOMElementPtr m_pRoot; //the root element
MSXML2::IXMLDOMDocumentPtr m_pDoc; //the xml document

HRESULT hr = m_pDoc->CreateInstance(__uuidof(MSXML2::DOMDocument));
if(FAILED(hr))
{
cout<<"Failed to create the instance of Document."<<endl;
return 1;
}
else
{
m_pDoc->load("contact.xml");
//#1. m_pRoot points to 0x00000000 after this step
hr = m_pDoc->get_documentElement(&m_pRoot);
m_pElement = m_pDoc->createElement("index");
m_pElement->setAttribute("firstchar",firstchar);
//#2. the CXX0030 error occurs in this step
m_pRoot->appendChild(m_pElement);

m_pChildElement = m_pDoc->createElement("contact");
m_pChildElement->setAttribute("id",_variant_t(conInfo.id));
m_pChildElement->setAttribute("name",_variant_t(fullname));
m_pElement->appendChild(m_pChildElement);

MSXML2::IXMLDOMElementPtr pElement;
MSXML2::IXMLDOMElementPtr pExtElement;
pElement = m_pDoc->createElement("firstname");
pElement->put_text(conInfo.firstname.AllocSysString());
m_pChildElement->appendChild(pElement);
}

return 0;
}

Any suggestion is welcome!
Topic archived. No new replies allowed.