VirtualBox

Changeset 84062 in vbox


Ignore:
Timestamp:
Apr 28, 2020 7:20:30 PM (5 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
137641
Message:

FE/Qt: Corrected a bunch of misconseptions in the two HRESULT formatters about what RTErrCOMGet returns. Prepared for new windows interface in that area (disabled). bugref:9726

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UIErrorString.cpp

    r82968 r84062  
    3333QString UIErrorString::formatRC(HRESULT rc)
    3434{
    35     QString str;
    36 
    37     PCRTCOMERRMSG msg = NULL;
    38     const char *pErrMsg = NULL;
    39 
    40     /* First, try as is (only set bit 31 bit for warnings): */
    41     if (SUCCEEDED_WARNING(rc))
    42         msg = RTErrCOMGet(rc | 0x80000000);
     35    /** @todo r=bird: Not sure why we set the sign bit 31 bit for warnings.
     36     *  Maybe to try get the error variant?  It won't really work for S_FALSE and
     37     *  probably a bunch of others too.  I've modified it on windows to try get
     38     *  the exact one, the one with the top bit set, or just the value. */
     39#if 0//def RT_OS_WINDOWS
     40    char szDefine[80];
     41    if (!SUCCEEDED_WARNING(rc))
     42        RTErrWinQueryDefine(rc, szDefine, sizeof(szDefine), false /*fFailIfUnknown*/);
    4343    else
    44         msg = RTErrCOMGet(rc);
    45 
    46     if (msg != NULL)
    47         pErrMsg = msg->pszDefine;
    48 
    49 #ifdef VBOX_WS_WIN
    50     PCRTWINERRMSG winMsg = NULL;
    51 
    52     /* If not found, try again using RTErrWinGet with masked off top 16bit: */
    53     if (msg == NULL)
    54     {
    55         winMsg = RTErrWinGet(rc & 0xFFFF);
    56 
    57         if (winMsg != NULL)
    58             pErrMsg = winMsg->pszDefine;
    59     }
    60 #endif /* VBOX_WS_WIN */
    61 
    62     if (pErrMsg != NULL && *pErrMsg != '\0')
    63         str.sprintf("%s", pErrMsg);
    64 
    65     return str;
     44    {
     45        if (   RTErrWinQueryDefine(rc, szDefine, sizeof(szDefine), true /*fFailIfUnknown*/) < 0
     46            || RTErrWinQueryDefine(rc | 0x80000000, szDefine, sizeof(szDefine), true /*fFailIfUnknown*/) < 0)
     47            RTErrWinQueryDefine(rc, szDefine, sizeof(szDefine), false /*fFailIfUnknown*/);
     48    }
     49
     50    QString str;
     51    str.sprintf("%s", szDefine);
     52    return str;
     53#else
     54    const char *pszDefine = RTErrCOMGet(SUCCEEDED_WARNING(rc) ? rc | 0x80000000 : rc)->pszDefine;
     55    Assert(pszDefine);
     56
     57    QString str;
     58    str.sprintf("%s", pszDefine);
     59    return str;
     60#endif
    6661}
    6762
     
    6964QString UIErrorString::formatRCFull(HRESULT rc)
    7065{
    71     QString str;
    72 
    73     PCRTCOMERRMSG msg = NULL;
    74     const char *pErrMsg = NULL;
    75 
    76     /* First, try as is (only set bit 31 bit for warnings): */
    77     if (SUCCEEDED_WARNING(rc))
    78         msg = RTErrCOMGet(rc | 0x80000000);
     66    /** @todo r=bird: See UIErrorString::formatRC for 31th bit discussion. */
     67#if 0//def RT_OS_WINDOWS
     68    char szDefine[80];
     69    ssize_t cchRet = RTErrWinQueryDefine(rc, szDefine, sizeof(szDefine), true /*fFailIfUnknown*/);
     70    if (RT_FAILURE(cchRet) && SUCCEEDED_WARNING(rc)))
     71        cchRet = RTErrWinQueryDefine(rc | 0x80000000, szDefine, sizeof(szDefine), true /*fFailIfUnknown*/);
     72
     73    QString str;
     74    if (RT_SUCCESS(cchRet))
     75        str.sprintf("%s (0x%08x)", szDefine, rc);
    7976    else
    80         msg = RTErrCOMGet(rc);
    81 
    82     if (msg != NULL)
    83         pErrMsg = msg->pszDefine;
    84 
    85 #ifdef VBOX_WS_WIN
    86     PCRTWINERRMSG winMsg = NULL;
    87 
    88     /* If not found, try again using RTErrWinGet with masked off top 16bit: */
    89     if (msg == NULL)
    90     {
    91         winMsg = RTErrWinGet(rc & 0xFFFF);
    92 
    93         if (winMsg != NULL)
    94             pErrMsg = winMsg->pszDefine;
    95     }
    96 #endif /* VBOX_WS_WIN */
    97 
    98     if (pErrMsg != NULL && *pErrMsg != '\0')
    99         str.sprintf("%s (0x%08X)", pErrMsg, rc);
     77        str.sprintf("0x%08x", rc);
     78    return str;
     79#else
     80    const char *pszDefine = RTErrCOMGet(SUCCEEDED_WARNING(rc) ? rc | 0x80000000 : rc)->pszDefine;
     81    Assert(pszDefine);
     82
     83    QString str;
     84    if (strncmp(pszDefine, RT_STR_TUPLE("Unknown ")))
     85        str.sprintf("%s (0x%08X)", pszDefine, rc);
    10086    else
    10187        str.sprintf("0x%08X", rc);
    102 
    103     return str;
     88    return str;
     89#endif
    10490}
    10591
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette