[與此頁面相關聯的功能,DirectShow是舊版功能。 它已被 MediaPlayer、IMFMediaEngine以及媒體基礎架構中的音訊/視訊擷取取代。 這些功能已針對 Windows 10 和 Windows 11 進行優化。 Microsoft強烈建議新程式代碼盡可能在媒體 基礎中使用 MediaPlayer、IMFMediaEngine 和 音訊/視訊擷取,而不是 DirectShow。 Microsoft建議使用舊版 API 的現有程式代碼,盡可能改寫成使用新的 API。]
[此 API 不受支持,未來可能會改變或無法使用。]
IAMErrorLog 介面包含單一方法,LogError。 方法的參數包含所發生錯誤的相關信息。
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.
錯誤碼和錯誤字串是由 DirectShow 編輯服務所定義。 如需錯誤清單,請參閱 轉譯錯誤。
pExtraInfo 參數包含一個指向 VARIANT 類型的指標,其中存有關於錯誤的其他資訊。 VARIANT 的數據類型和內容取決於發生的特定錯誤。 例如,如果錯誤是由不正確的檔名所造成,VARIANT 是具有不良檔名的字串。 某些錯誤沒有額外的資訊,所以 pExtraInfo 可能是 NULL。 下列程式代碼示範如何測試 VARIANT 的 vt 成員,這會指出數據類型,並據此格式化訊息。
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);
}
注意
切勿釋放指向的 VARIANT
| 標籤 | 價值 |
|---|---|
|
. 此外,VARIANT 會在方法傳回之後變成無效,因此請稍後不要參考它。
相關主題