Compartir a través de


Método IMFMediaEventGenerator::BeginGetEvent (mfobjects.h)

Inicia una solicitud asincrónica para el siguiente evento de la cola.

Sintaxis

HRESULT BeginGetEvent(
  [in] IMFAsyncCallback *pCallback,
  [in] IUnknown         *punkState
);

Parámetros

[in] pCallback

Puntero a la interfaz IMFAsyncCallback de un objeto de devolución de llamada. El cliente debe implementar esta interfaz.

[in] punkState

Puntero a la interfaz IUnknown de un objeto de estado, definido por el autor de la llamada. Este parámetro puede ser NULL. Puede usar este objeto para contener información de estado. El objeto se devuelve al autor de la llamada cuando se invoca la devolución de llamada.

Valor devuelto

El método devuelve un valor HRESULT. Entre los valores posibles se incluyen los que se indican en la tabla siguiente, entre otros.

Código devuelto Descripción
S_OK
El método se ha llevado a cabo de forma correcta.
E_INVALIDARG
Argumento de puntero NULL.
MF_E_MULTIPLE_BEGIN
Hay una solicitud pendiente con el mismo puntero de devolución de llamada y un objeto de estado diferente.
MF_E_MULTIPLE_SUBSCRIBERS
Hay una solicitud pendiente con un puntero de devolución de llamada diferente.
MF_E_SHUTDOWN
El objeto se cerró.
MF_S_MULTIPLE_BEGIN
Hay una solicitud pendiente con el mismo puntero de devolución de llamada y objeto de estado.

Comentarios

Cuando hay disponible un nuevo evento, el generador de eventos llama al método IMFAsyncCallback::Invoke . El método Invoke debe llamar a IMFMediaEventGenerator::EndGetEvent para obtener un puntero a la interfaz IMFMediaEvent y usar esa interfaz para examinar el evento.

No llame a BeginGetEvent una segunda vez antes de llamar a EndGetEvent. Aunque la primera llamada sigue pendiente, se producirá un error en las llamadas adicionales al mismo objeto. Además, se produce un error en el método IMFMediaEventGenerator::GetEvent si una solicitud asincrónica sigue pendiente.

Ejemplos

El código siguiente muestra una implementación típica de IMFAsyncCallback::Invoke para el método BeginGetEvent . El método Invoke llama a EndGetEvent para obtener los datos del evento. A continuación, llama a BeginGetEvent de nuevo para solicitar otro evento.

//////////////////////////////////////////////////////////////////////
//  Name: CEventHandler::Invoke
//  Callback for asynchronous BeginGetEvent method.
//
//  pAsyncResult: Pointer to the result.
//
//  This code example assumes that CEventHandler is a class that 
//  implements the IMFAsyncCallback interface. 
///////////////////////////////////////////////////////////////////////
HRESULT CEventHandler::Invoke(IMFAsyncResult *pAsyncResult)
{
    HRESULT hr = S_OK;
    IMFMediaEvent* pEvent = NULL;
    MediaEventType meType = MEUnknown;
    BOOL fGetAnotherEvent = TRUE;
    HRESULT hrStatus = S_OK;

    // Get the event from the event queue.
    // Assume that m_pEventGenerator is a valid pointer to the
    // event generator's IMFMediaEventGenerator interface.
    hr = m_pEventGenerator->EndGetEvent(pAsyncResult, &pEvent);

    // Get the event type.
    if (SUCCEEDED(hr))
    {
        hr = pEvent->GetType(&meType);
    }

    // Get the event status. If the operation that triggered the event 
    // did not succeed, the status is a failure code.
    if (SUCCEEDED(hr))
    {
        hr = pEvent->GetStatus(&hrStatus);
    }

    if (SUCCEEDED(hr))
    {
        // TODO: Handle the event.
    }

    // If not finished, request another event.
    // Pass in a pointer to this instance of the application's
    // CEventHandler class, which implements the callback.
    if (fGetAnotherEvent)
    {
        hr = m_pEventGenerator->BeginGetEvent(this, NULL);
    }

    SAFE_RELEASE(pEvent);
    return hr;
}

Requisitos

Requisito Value
Cliente mínimo compatible Windows Vista [aplicaciones de escritorio | aplicaciones para UWP]
Servidor mínimo compatible Windows Server 2008 [aplicaciones de escritorio | aplicaciones para UWP]
Plataforma de destino Windows
Encabezado mfobjects.h (include Mfidl.h)
Library Mfuuid.lib

Consulte también

IMFMediaEventGenerator

Generadores de eventos multimedia