【发布时间】:2012-08-23 13:29:04
【问题描述】:
我正在开发一个 COM DLL,但遇到了一些问题。我对一段代码进行了尝试捕获,在捕获中我从异常中得到了_bstr_t。我想要做的是捕获该异常并将其打印到一个字符串中,但是,当该异常被抛出时,它会向我抛出一个无效的空指针错误。我尝试查看有关如何检查空指针的 MSDN,但它似乎不起作用。我无法真正调试该错误,因为这是在客户端计算机上,并且在尝试输出信息时出现此错误。
catch(const _com_error& ex)
{
::OutputDebugStringW(ex.Description());
_variant_t ret;
std::string str = "#N/A ExcelException: ";
_bstr_t desc = ex.Description();
if(!desc || desc.GetBSTR() == L"")
{
str += ConvertBSTRToMBS(desc);
}
ret.SetString(str.c_str());
*Result = ret.Detach();
}
std::string ConvertBSTRToMBS(_bstr_t bstr)
{
std::string converted((char *)bstr);
return converted;
}
【问题讨论】:
标签: c++ string exception com bstr