Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

load xml using vc++

Status
Not open for further replies.

smythe

Programmer
May 30, 2001
49
US
I'm using the XMLDOM methodology to parse a XML file using visual c++....

I do something like this:

#import "msxml4.dll"
using namespace MSXML2;
inline void EVAL_HR( HRESULT _hr )
{ if FAILED(_hr) throw(_hr); }

Then I begin to load the xml document into the XMLDOM objects like so...

IXMLDOMDocument2Ptr m_pXMLDOM ;
IXMLDOMElementPtr m_pRootElem ;

m_pXMLDOM = NULL ;
m_pRootElem = NULL ;

EVAL_HR( m_pXMLDOM.CreateInstance("Msxml2.DOMDocument.4.0") ) ;
m_pXMLDOM->async = false;

if (!m_pXMLDOM->load((LPCTSTR)cstrXMLFileName))
{
CString cstrErrorMessage ;
AfxMessageBox("3") ;
cstrErrorMessage.Format (" %s\n\nerror=%d\nurl=%s\ntext=%s\nline=%d\npos=%d\n
filepos=%d",
(LPCTSTR)m_pXMLDOM->parseError->Getreason(),
m_pXMLDOM->parseError->errorCode,
(LPCTSTR)m_pXMLDOM->parseError->url,
(LPCTSTR)m_pXMLDOM->parseError->srcText,
m_pXMLDOM->parseError->line,
m_pXMLDOM->parseError->linepos,
m_pXMLDOM->parseError->filepos) ;

AfxMessageBox (cstrErrorMessage) ;

AfxThrowUserException( );
} ;

EVAL_HR(m_pXMLDOM->get_documentElement(&m_pRootElem) );


When I debug... the application crashes on the
EVAL_HR( m_pXMLDOM.CreateInstance("Msxml2.DOMDocument.4.0") ) ;
line. The debugger gives me the following exception:

UNHANDLED EXCEPTION
KERNEL32.DLL 0xE06D7363

Any ideas? The strange part is that replicate code works in a different class of the same project... I've double checked and the code is exactly the same.
 
Well potentially at the surface your macro EVAL_HR is throwing an exception (by design) and the code you posted is not catching the exception and hence the UNHANDLED EXCEPTION error.

Next, I recommend using _com_util::CheckError() rather than writing your own exception mechanism. This throws a
Code:
_com_error


-pete
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top