COM error problems: _com_error and _b_str_t
I am having one hell of a time trying to implement XML parsing,
because of all the COM business that MSXML6 uses. Anyway, my latest
problem is that I tryed to incorperate some error handling. When I
catch a _com_error from a call made on the MSXML smart ptr interfaces
I try to get the error message or description and put it in my own
exception. When I try to assign _com_error::Description() to a
std::string or insert it to a stringstream using <<, I get another
exception of unknown type and the debugger points to assembly.
How can I safely get the error message from a _com_error object and
put it into a std::string in a multibyte project?
Here is my offending code:
//--------------------------------------------------------------------------------------------------------------------
void DataManager::ParseGoods(MSXML2::IXMLDOMNodeListPtr &
goodXMLNodes)
{
BaseException error("Unspecified Error",
"void
DataManager::ParseGoods(MSXML2::IXMLDOMNodeListPtr & goodXMLNodes)",
"DataManager.cpp");
for(Good::ID id = 0; id < static_cast<unsigned>(goodXMLNodes-
Getlength()); ++id)
{
MSXML2::IXMLDOMNodePtr node = goodXMLNodes->nextNode();
Good good;
good.m_ID = id;
for(node = node->GetfirstChild(); node != NULL; node = node-
GetnextSibling())
{
std::string element = node->nodeName;
if( element == "name" || element == "Name" )
{
try
{
good.m_name = node->GetnodeTypedValue();
}
catch(_com_error & e)
{
std::ostringstream errorMsg;
errorMsg << "Error parsing <good> node #" << id << ".
\n"
<< "Could not get typed value of <name>
element.\n\n"
<< "COM error description: " <<
e.Description();
error.m_msg = errorMsg.str();
throw error;
}
}
*snip*
---------------------------------------------
I have tryed:
1) << std::string(e.Description());
2) << e.Description.operator const char*();
3) + e.Description
The MSDN documentation on the returned _b_str_t implies that it can be
converted to a regualr const char *, so I do not understand the
problem. Is the damn thing empty? How am I supposed to do this the
right way?