Creazione di una classe di registrazione degli errori
[La funzionalità associata a questa pagina, DirectShow, è una funzionalità legacy. È stata sostituita da MediaPlayer, FMMediaEngine e Audio/Video Capture in Media Foundation. Queste funzionalità sono state ottimizzate per Windows 10 e Windows 11. Microsoft consiglia vivamente che il nuovo codice usi MediaPlayer, FMMediaEngine e Audio/Video Capture in Media Foundation anziché DirectShow, quando possibile. Microsoft suggerisce che il codice esistente che usa le API legacy venga riscritto per usare le nuove API, se possibile.
[Questa API non è supportata e può essere modificata o non disponibile in futuro.]
Questo argomento descrive come implementare la registrazione degli errori in DirectShow Editing Services.
In primo luogo, dichiarare una classe che implementerà la registrazione degli errori. La classe eredita l'interfaccia IAMErrorLog . Contiene dichiarazioni per i tre metodi IUnknown e per il singolo metodo in IAMErrorLog. La dichiarazione di classe è la seguente:
class CErrReporter : public IAMErrorLog
{
protected:
long m_lRef; // Reference count.
public:
CErrReporter() { m_lRef = 0; }
// IUnknown
STDMETHOD(QueryInterface(REFIID, void**));
STDMETHOD_(ULONG, AddRef());
STDMETHOD_(ULONG, Release());
// IAMErrorLog
STDMETHOD(LogError(LONG, BSTR, LONG, HRESULT, VARIANT*));
};
L'unica variabile membro nella classe è m_lRef, che contiene il conteggio dei riferimenti dell'oggetto.
Definire quindi i metodi in IUnknown. Nell'esempio seguente viene illustrata un'implementazione standard per questi metodi:
STDMETHODIMP CErrReporter::QueryInterface(REFIID riid, void **ppv)
{
if (ppv == NULL) return E_POINTER;
*ppv = NULL;
if (riid == IID_IUnknown)
*ppv = static_cast<IUnknown*>(this);
else if (riid == IID_IAMErrorLog)
*ppv = static_cast<IAMErrorLog*>(this);
else
return E_NOINTERFACE;
AddRef();
return S_OK;
}
STDMETHODIMP_(ULONG) CErrReporter::AddRef()
{
return InterlockedIncrement(&m_lRef);
}
STDMETHODIMP_(ULONG) CErrReporter::Release()
{
// Store the decremented count in a temporary
// variable.
ULONG uCount = InterlockedDecrement(&m_lRef);
if (uCount == 0)
{
delete this;
}
// Return the temporary variable, not the member
// variable, for thread safety.
return uCount;
}
Con il framework COM, è ora possibile implementare l'interfaccia IAMErrorLog . La sezione successiva descrive come eseguire questa operazione.
Argomenti correlati