Microsoft DirectX 8.1 (C++)

Implementing IAMErrorLog

The IAMErrorLog interface contains a single method, LogError. The parameters to the method contain information about the error that occurred.

STDMETHODIMP LogError(
    LONG Severity,          // Reserved. Do not use.
    BSTR ErrorString,       // Description.
    LONG ErrorCode,         // Error code.
    HRESULT hresult,        // HRESULT that caused the error.
    VARIANT *pExtraInfo);   // Extra information about the error.

The error code and the error string are defined by DirectShow Editing Services. For a list of errors, see Rendering Errors.

The pExtraInfo parameter contains a pointer to a VARIANT type that holds additional information about the error. The data type and contents of the VARIANT depend on the specific error that occurred. For example, if the error was caused by an incorrect file name, the VARIANT is a string with the bad file name. Some errors do not have extra information, so pExtraInfo might be NULL. The following code shows how to test the vt member of the VARIANT, which indicates the data type, and format a message accordingly.

if( pExtraInfo )    // Report extra information, if any. 
{                           
    printf("\tExtra info: ");
    if( pExtraInfo->vt == VT_BSTR )      // Extra info is a BSTR.
    {
        char szExtra[256];
        WideCharToMultiByte(CP_ACP, 0, pExtraInfo->bstrVal, -1, szExtra, 256, 0, 0);
        printf("%s\n", szExtra);
    } 
    else if( pExtraInfo->vt == VT_I4 )   // Extra info is an integer.
        printf("%d\n", pExtraInfo->lVal);

    else if( pExtraInfo->vt == VT_R8 )   // Extra info is floating-point.
        printf("%f\n", pExtraInfo->dblVal);
}

Note   Do not free the VARIANT pointed to by pExtraInfo. Also, the VARIANT becomes invalid after the method returns, so do not reference it later.