Getting Error Messages from a Sink
[The feature associated with this page, Windows Media Format 11 SDK, is a legacy feature. It has been superseded by Source Reader and Sink Writer. Source Reader and Sink Writer have been optimized for Windows 10 and Windows 11. Microsoft strongly recommends that new code use Source Reader and Sink Writer instead of Windows Media Format 11 SDK, when possible. Microsoft suggests that existing code that uses the legacy APIs be rewritten to use the new APIs if possible.]
The writer object does not send messages to the IWMStatusCallback::OnStatus callback method. However, you can set writer sinks to send messages to OnStatus. Each sink must be set to deliver status separately, but all sinks can report to the same callback.
To set a sink to deliver status messages to OnStatus, call the IWMRegisterCallback::Advise method.
The following example code demonstrates how to set all of the sinks to deliver status messages to an OnStatus callback. In this example, the index of each sink will be used as the context parameter so that the OnStatus method can differentiate between messages from the different sinks. For more information about using this code, see Using the Code Examples.
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;
}
Related topics