Path: blob/master/samples/winrt/ImageManipulations/MediaExtensions/Common/AsyncCB.h
16349 views
#pragma once12//////////////////////////////////////////////////////////////////////////3// AsyncCallback [template]4//5// Description:6// Helper class that routes IMFAsyncCallback::Invoke calls to a class7// method on the parent class.8//9// Usage:10// Add this class as a member variable. In the parent class constructor,11// initialize the AsyncCallback class like this:12// m_cb(this, &CYourClass::OnInvoke)13// where14// m_cb = AsyncCallback object15// CYourClass = parent class16// OnInvoke = Method in the parent class to receive Invoke calls.17//18// The parent's OnInvoke method (you can name it anything you like) must19// have a signature that matches the InvokeFn typedef below.20//////////////////////////////////////////////////////////////////////////2122// T: Type of the parent object23template<class T>24class AsyncCallback : public IMFAsyncCallback25{26public:27typedef HRESULT (T::*InvokeFn)(IMFAsyncResult *pAsyncResult);2829AsyncCallback(T *pParent, InvokeFn fn) : m_pParent(pParent), m_pInvokeFn(fn)30{31}3233// IUnknown34STDMETHODIMP_(ULONG) AddRef() {35// Delegate to parent class.36return m_pParent->AddRef();37}38STDMETHODIMP_(ULONG) Release() {39// Delegate to parent class.40return m_pParent->Release();41}42STDMETHODIMP QueryInterface(REFIID iid, void** ppv)43{44if (!ppv)45{46return E_POINTER;47}48if (iid == __uuidof(IUnknown))49{50*ppv = static_cast<IUnknown*>(static_cast<IMFAsyncCallback*>(this));51}52else if (iid == __uuidof(IMFAsyncCallback))53{54*ppv = static_cast<IMFAsyncCallback*>(this);55}56else57{58*ppv = NULL;59return E_NOINTERFACE;60}61AddRef();62return S_OK;63}646566// IMFAsyncCallback methods67STDMETHODIMP GetParameters(DWORD*, DWORD*)68{69// Implementation of this method is optional.70return E_NOTIMPL;71}7273STDMETHODIMP Invoke(IMFAsyncResult* pAsyncResult)74{75return (m_pParent->*m_pInvokeFn)(pAsyncResult);76}7778T *m_pParent;79InvokeFn m_pInvokeFn;80};818283