zoukankan      html  css  js  c++  java
  • VC2010 _com_error 返回的错误信息

     1 CString GetComError(const _com_error& e)
     2 {
     3     CString sMsg;
     4     sMsg.Format(
     5         _T("HRESULT: 0x%08lx; Error: %s"),
     6         e.Error(),
     7         e.ErrorMessage()
     8         );
     9 
    10     if(e.ErrorInfo())
    11     {
    12         sMsg += TEXT("
    Source: ") + CString((LPCTSTR)e.Source()) +
    13             TEXT("; Description: ") + CString((LPCTSTR)e.Description());
    14     }
    15 
    16     return sMsg;
    17 }


    注意上面红色的地方,要进行数据类型转换,否则会出现乱码。

    例如:VC2010 用ADO 连接数据库时,e.Description()前一定要加(LPCTSTR)

     1     try
     2     {
     3         m_pConnection->Open((_bstr_t)lpszConnectString,"","",adModeUnknown);
     4     }
     5     catch (_com_error &e)
     6     {
     7         m_strErrorString.Format("%s:%s",e.ErrorMessage(),(LPCTSTR)e.Description());
     8         AfxMessageBox(m_strErrorString);
     9         return false;
    10     }
  • 相关阅读:
    第四次作业
    第三次作业
    第二次作业。
    国庆作业。
    实验2-4
    实验2-3
    实验2-2
    实验2-1
    实验1-3
    实验 1-1
  • 原文地址:https://www.cnblogs.com/wolfplan/p/3912785.html
Copyright © 2011-2022 走看看