The ShowException Function

If an error occurs as the result of an Invoke function call, the ShowException function attempts to display information about the exception. Note that this function uses a global window handle, which must be set before this function can be called.

void ShowException(LPOLESTR szMember, HRESULT hr, EXCEPINFO *pexcep, 
    unsigned int uiArgErr)
{
    TCHAR szBuf[512];

    switch (GetScode(hr)) 
    {
        case DISP_E_UNKNOWNNAME:
            wsprintf(szBuf, L"%s: Unknown name or named argument.", 
                szMember);
            break;

        case DISP_E_BADPARAMCOUNT:
            wsprintf(szBuf, L"%s: Incorrect number of arguments.", 
                szMember);
            break;

        case DISP_E_EXCEPTION:
            wsprintf(szBuf, L"%s: Error %d: ", szMember, pexcep->wCode);
            if (pexcep->bstrDescription != NULL)
                lstrcat(szBuf, pexcep->bstrDescription);
            else
                lstrcat(szBuf, L"<<No Description>>");
            break;

        case DISP_E_MEMBERNOTFOUND:
            wsprintf(szBuf, L"%s: method or property not found.", 
                szMember);
            break;

        case DISP_E_OVERFLOW:
            wsprintf(szBuf, L"%s: Overflow while coercing argument 
                values.", szMember);
            break;

        case DISP_E_NONAMEDARGS:
            wsprintf(szBuf, L"%s: Object implementation does not support 
                named arguments.", szMember);
            break;

        case DISP_E_UNKNOWNLCID:
            wsprintf(szBuf, L"%s: The locale ID is unknown.", szMember);
            break;

        case DISP_E_PARAMNOTOPTIONAL:
            wsprintf(szBuf, L"%s: Missing a required parameter.", 
                szMember);
            break;

        case DISP_E_PARAMNOTFOUND:
            wsprintf(szBuf, L"%s: Argument not found, argument %d.", 
                szMember, uiArgErr);
            break;

        case DISP_E_TYPEMISMATCH:
            wsprintf(szBuf, L"%s: Type mismatch, argument %d.", 
                szMember, uiArgErr);
            break;

        default:
            wsprintf(szBuf, L"%s: Unknown error occured.", szMember);
            break;
    }

    MessageBox(g_hwndApp, szBuf, g_szAppTitle, MB_OK | MB_ICONSTOP);
}