Microsoft DirectX 9.0

Implementing IAMErrorLog

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

    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.
        UINT len = SysStringLen(pExtraInfo->bstrVal);
        char *szExtra = new char[len];
        if (szExtra != NULL)
            // Note - If the BSTR contains embedded NULL characters, this
            // will only pick up the first sub-string.
            WideCharToMultiByte(CP_ACP, 0, pExtraInfo->bstrVal, -1, 
                szExtra, len, 0, 0);
            printf("%s\n", szExtra);
            delete [] 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.