共用方式為


從終端獲取錯誤訊息

[與此頁面相關聯的功能 Windows Media Format 11 SDK是舊版功能。 資料讀取器資料寫入器已經取代了該技術。 來源讀取器接收寫入器 已針對 Windows 10 和 Windows 11 優化。 Microsoft強烈建議新的程式碼盡可能使用 來源讀取器接收端寫入器,而不是 Windows Media Format 11 SDK。 Microsoft建議使用舊版 API 的現有程式代碼,盡可能改寫成使用新的 API。]

寫入器物件不會將訊息傳送至 IWMStatusCallback::OnStatus 回呼方法。 不過,您可以設定寫入器接收,將訊息傳送至 OnStatus。 每個匯流點必須個別設定以傳送狀態,但所有匯流點可以報告到相同的回呼。

若要將接收器設定為將狀態訊息傳遞至 OnStatus,請呼叫 IWMRegisterCallback::Advise 方法。

下列範例程式碼示範如何將所有匯流排設定為將狀態訊息傳送至 OnStatus 回呼。 在此範例中,每個接收器的索引會作為上下文參數使用,使 OnStatus 方法可以區分來自不同接收器的訊息。 如需使用此程式碼的詳細資訊,請參閱 使用程式碼範例

HRESULT SetSinksForStatus (IWMWriter* pWriter, IWMStatusCallback* pStatus)
{
    HRESULT hr          = S_OK;
    DWORD   cSinks      = 0;
    DWORD   dwSinkIndex = 0;

    IWMWriterAdvanced*   pWriterAdvanced = NULL;
    IWMWriterSink*       pSink           = NULL;
    IWMRegisterCallback* pRegisterCallbk = NULL;

    // Get the advanced writer interface.
    hr = pWriter->QueryInterface(IID_IWMWriterAdvanced, 
                                 (void**)&pWriterAdvanced);
    GOTO_EXIT_IF_FAILED(hr);

    // Get the number of sinks that are added to the writer object.
    hr = pWriterAdvanced->GetSinkCount(&cSinks);
    GOTO_EXIT_IF_FAILED(hr);

    // Loop through all of the sinks.
    for(dwSinkIndex = 0; dwSinkIndex < cSinks; dwSinkIndex++)
    {
        // Get the base interface for the next sink.
        hr = pWriterAdvanced->GetSink(dwSinkIndex, &pSink);
        GOTO_EXIT_IF_FAILED(hr);

        // Get the callback registration interface for the sink.
        hr = pSink->QueryInterface(IID_IWMRegisterCallback,
                                   (void**)&pRegisterCallbk);
        GOTO_EXIT_IF_FAILED(hr);

        // Register the OnStatus callback.
        hr = pRegisterCallbk->Advise(pStatus, (void*) &dwSinkIndex);
        GOTO_EXIT_IF_FAILED(hr);

        // Release for the next iteration.
        SAFE_RELEASE(pSink);
        SAFE_RELEASE(pRegisterCallbk);
    } // end for dwSinkIndex

Exit:
    SAFE_RELEASE(pSink);
    SAFE_RELEASE(pRegisterCallbk);
    SAFE_RELEASE(pWriterAdvanced);
    return hr;
}

IWMRegisterCallback 介面

與寫入器接收端合作