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);